fix status page api

This commit is contained in:
Simon Larsen 2022-12-29 17:14:29 +00:00
parent 41262db51a
commit 0a7abb5a3b
13 changed files with 99 additions and 137 deletions

View File

@ -1 +1 @@
ONEUPTIME_SECRET=ae60cf8f0cec2df8d05aaf0b
ONEUPTIME_SECRET=fd57b59aa8f3f516d2f6cb06

View File

@ -13,7 +13,7 @@ router.get('/', (_req: ExpressRequest, res: ExpressResponse) => {
// General status
router.get('/status', (_req: ExpressRequest, res: ExpressResponse) => {
res.send({ status: 'status' });
res.send({ status: 'ok' });
});
//Healthy probe

View File

@ -51,6 +51,9 @@ import ScheduledMaintenanceStateTimelineService from '../Services/ScheduledMaint
import DatabaseCommonInteractionProps from 'Common/Types/Database/DatabaseCommonInteractionProps';
import Query from '../Types/Database/Query';
import JSONFunctions from 'Common/Types/JSONFunctions';
import GreenlockChallenge from 'Model/Models/GreenlockChallenge';
import GreenlockChallengeService from '../Services/GreenlockChallengeService';
import NotFoundException from 'Common/Types/Exception/NotFoundException';
export default class StatusPageAPI extends BaseAPI<
StatusPage,
@ -59,6 +62,75 @@ export default class StatusPageAPI extends BaseAPI<
public constructor() {
super(StatusPage, StatusPageService);
// CNAME verification api
this.router.get(
`${new this.entityType().getCrudApiPath()?.toString()}/status-page-api/cname-verification/:token`,
async (req: ExpressRequest, res: ExpressResponse) => {
const host: string | undefined = req.get('host');
if (!host) {
throw new BadDataException('Host not found');
}
const domain: StatusPageDomain | null =
await StatusPageDomainService.findOneBy({
query: {
cnameVerificationToken: req.params['token'] as string,
fullDomain: host,
},
select: {
_id: true,
},
props: {
isRoot: true,
},
});
if (!domain) {
return Response.sendErrorResponse(
req,
res,
new BadDataException('Invalid token.')
);
}
return Response.sendEmptyResponse(req, res);
}
);
// ACME Challenge Validation.
this.router.get(
`${new this.entityType().getCrudApiPath()?.toString()}/.well-known/acme-challenge/:token`,
async (req: ExpressRequest, res: ExpressResponse) => {
const challenge: GreenlockChallenge | null =
await GreenlockChallengeService.findOneBy({
query: {
token: req.params['token'] as string,
},
select: {
challenge: true,
},
props: {
isRoot: true,
},
});
if (!challenge) {
return Response.sendErrorResponse(
req,
res,
new NotFoundException('Challenge not found')
);
}
return Response.sendTextResponse(
req,
res,
challenge.challenge as string
);
}
);
this.router.post(
`${new this.entityType().getCrudApiPath()?.toString()}/domain`,
UserMiddleware.getUserMiddleware,

View File

@ -121,10 +121,6 @@ app.get(
}
);
app.get('/status', (_req: ExpressRequest, res: ExpressResponse) => {
res.redirect('https://status.oneuptime.com');
});
app.get(
'/product/uptime-monitoring',
(_req: ExpressRequest, res: ExpressResponse) => {

View File

@ -22,10 +22,6 @@ upstream status-page {
server status-page:3105 weight=10 max_fails=3 fail_timeout=30s;
}
upstream status-page-api {
server status-page:3106 weight=10 max_fails=3 fail_timeout=30s;
}
upstream home {
server home:1444 weight=10 max_fails=3 fail_timeout=30s;
}
@ -94,7 +90,7 @@ server {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://status-page-api;
proxy_pass http://dashboard-api/status-page/status-page-api;
}
# Acme Verification.
@ -109,8 +105,9 @@ server {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://status-page-api;
proxy_pass http://dashboard-api/status-page/.well-known;
}
}
server {

View File

@ -1 +1 @@
PORT={{ .Env.STATUS_PAGE_API_PORT }}
PORT={{ .Env.STATUS_PAGE_PORT }}

View File

@ -1,107 +0,0 @@
import App from 'CommonServer/Utils/StartServer';
import Express, {
ExpressApplication,
ExpressRequest,
ExpressResponse,
} from 'CommonServer/Utils/Express';
import logger from 'CommonServer/Utils/Logger';
import { PostgresAppInstance } from 'CommonServer/Infrastructure/PostgresDatabase';
import GreenlockChallengeService from 'CommonServer/Services/GreenlockChallengeService';
import GreenlockChallenge from 'Model/Models/GreenlockChallenge';
import Response from 'CommonServer/Utils/Response';
import NotFoundException from 'Common/Types/Exception/NotFoundException';
import BadDataException from 'Common/Types/Exception/BadDataException';
import StatusPageDomain from 'Model/Models/StatusPageDomain';
import StatusPageDomainService from 'CommonServer/Services/StatusPageDomainService';
import Port from 'Common/Types/Port';
export const APP_NAME: string = 'status-page-api';
const app: ExpressApplication = Express.getExpressApp();
// ACME Challenge Validation.
app.get(
'/.well-known/acme-challenge/:token',
async (req: ExpressRequest, res: ExpressResponse) => {
const challenge: GreenlockChallenge | null =
await GreenlockChallengeService.findOneBy({
query: {
token: req.params['token'] as string,
},
select: {
challenge: true,
},
props: {
isRoot: true,
},
});
if (!challenge) {
return Response.sendErrorResponse(
req,
res,
new NotFoundException('Challenge not found')
);
}
return Response.sendTextResponse(
req,
res,
challenge.challenge as string
);
}
);
app.get(
'/status-page-api/cname-verification/:token',
async (req: ExpressRequest, res: ExpressResponse) => {
const host: string | undefined = req.get('host');
if (!host) {
throw new BadDataException('Host not found');
}
const domain: StatusPageDomain | null =
await StatusPageDomainService.findOneBy({
query: {
cnameVerificationToken: req.params['token'] as string,
fullDomain: host,
},
select: {
_id: true,
},
props: {
isRoot: true,
},
});
if (!domain) {
return Response.sendErrorResponse(
req,
res,
new BadDataException('Invalid token.')
);
}
return Response.sendEmptyResponse(req, res);
}
);
const init: Function = async (): Promise<void> => {
try {
// init the app
await App(APP_NAME, new Port(3106));
// connect to the database.
await PostgresAppInstance.connect(
PostgresAppInstance.getDatasourceOptions()
);
} catch (err) {
logger.error('App Init Failed:');
logger.error(err);
}
};
init();
export default app;

View File

@ -1,7 +1,6 @@
import App from 'CommonServer/Utils/StartServer';
import Express, { ExpressApplication } from 'CommonServer/Utils/Express';
import logger from 'CommonServer/Utils/Logger';
import Port from 'Common/Types/Port';
import { PostgresAppInstance } from 'CommonServer/Infrastructure/PostgresDatabase';
export const APP_NAME: string = 'status-page';
@ -10,7 +9,7 @@ const app: ExpressApplication = Express.getExpressApp();
const init: Function = async (): Promise<void> => {
try {
// init the app
await App(APP_NAME, new Port(3105), true);
await App(APP_NAME, undefined, true);
// connect to the database.
await PostgresAppInstance.connect(

View File

@ -1,5 +1,4 @@
{
"watch": ["./","../Common", "../CommonServer"],
"ext": "ts,json,tsx,env,js,jsx,hbs",
"exec": "node --inspect=0.0.0.0:9229 --require ts-node/register Index.ts"
"watch": ["webpack.config.js"],
"exec": "export DEBUG=express:* && webpack-dev-server --port=3105 --mode=development"
}

View File

@ -20,12 +20,11 @@
"use-async-effect": "^2.2.6"
},
"scripts": {
"dev": "webpack-dev-server --port=3105 --mode=development & nodemon",
"dev": "npx nodemon",
"build": "webpack build --mode=production",
"test": "react-app-rewired test",
"eject": "webpack eject",
"test": "",
"compile": "tsc",
"start": "node --require ts-node/register Serve.ts & node --require ts-node/register Index.ts",
"start": "node --require ts-node/register Serve.ts",
"audit": "npm audit --audit-level=low",
"preinstall": "npx npm-force-resolutions || echo 'No package-lock.json file. Skipping force resolutions'",
"dep-check": "depcheck ./ --skip-missing=true'"

View File

@ -71,7 +71,6 @@ REALTIME_PORT=3300
WORKERS_PORT=3452
ACCOUNTS_PORT=3003
STATUS_PAGE_PORT=3105
STATUS_PAGE_API_PORT=3106
DASHBOARD_PORT=3009
# Internal SMTP Server - Haraka

View File

@ -150,7 +150,6 @@ services:
status-page:
ports:
- '3105:3105' # HTTP UI Port
- '3106:3106' # HTTP API Port
{{ if eq .Env.ENVIRONMENT "development" }}
- 9764:9229 # Debugging port.
{{ end }}
@ -165,7 +164,6 @@ services:
restart: always
env_file:
- ./Common/.env
- ./CommonServer/.env
- ./CommonUI/.env
- ./StatusPage/.env

View File

@ -22,13 +22,23 @@ echo "We will need to wait ~5-10 minutes for things to settle down, migrations t
echo ""
echo "⏳ Waiting for OneUptime to boot (this will take a few minutes)"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/api/status)" != "200" ]]; do sleep 5; done'
echo "Progress 1/5"
echo "Progress 1/10"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/dashboard/status)" != "200" ]]; do sleep 5; done'
echo "Progress 2/5"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/status)" != "200" ]]; do sleep 5; done'
echo "Progress 3/5"
echo "Progress 2/10"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/file/status)" != "200" ]]; do sleep 5; done'
echo "Progress 3/10"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/staus-page/status)" != "200" ]]; do sleep 5; done'
echo "Progress 4/5"
echo "Progress 4/10"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/status)" != "200" ]]; do sleep 5; done'
echo "Progress 5/10"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/accounts/status)" != "200" ]]; do sleep 5; done'
echo "Progress 6/10"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/mail/status)" != "200" ]]; do sleep 5; done'
echo "Progress 7/10"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/workers/status)" != "200" ]]; do sleep 5; done'
echo "Progress 8/10"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/identity/status)" != "200" ]]; do sleep 5; done'
echo "Progress 9/10"
echo "⌛️ OneUptime is up!"
echo ""
echo "🎉🎉🎉 Done! 🎉🎉🎉"