mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
acme validation.
This commit is contained in:
@@ -9,6 +9,7 @@ enum ExceptionCode {
|
||||
NotAuthorizedException = 403,
|
||||
NotAuthenticatedxception = 401,
|
||||
PaymentRequiredException = 402,
|
||||
NotFoundException = 404,
|
||||
}
|
||||
|
||||
export default ExceptionCode;
|
||||
|
||||
8
Common/Types/Exception/NotFoundException.ts
Normal file
8
Common/Types/Exception/NotFoundException.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import Exception from './Exception';
|
||||
import ExceptionCode from './ExceptionCode';
|
||||
|
||||
export default class NotFoundException extends Exception {
|
||||
public constructor(message: string) {
|
||||
super(ExceptionCode.NotFoundException, message);
|
||||
}
|
||||
}
|
||||
@@ -243,4 +243,24 @@ export default class Response {
|
||||
oneUptimeResponse.status(200).send(item);
|
||||
this.logResponse(req, res, item as JSONObject);
|
||||
}
|
||||
|
||||
public static sendTextResponse(
|
||||
req: ExpressRequest,
|
||||
res: ExpressResponse,
|
||||
text: string
|
||||
): void {
|
||||
const oneUptimeRequest: OneUptimeRequest = req as OneUptimeRequest;
|
||||
const oneUptimeResponse: OneUptimeResponse = res as OneUptimeResponse;
|
||||
|
||||
oneUptimeResponse.set(
|
||||
'ExpressRequest-Id',
|
||||
oneUptimeRequest.id.toString()
|
||||
);
|
||||
|
||||
oneUptimeResponse.set('Pod-Id', process.env['POD_NAME']);
|
||||
|
||||
oneUptimeResponse.logBody = { text: text as string };
|
||||
oneUptimeResponse.status(200).send(text);
|
||||
this.logResponse(req, res, { text: text as string });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@ import Express, {
|
||||
ExpressStatic,
|
||||
} 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';
|
||||
|
||||
export const APP_NAME: string = 'status-page';
|
||||
|
||||
@@ -21,6 +26,30 @@ app.use(
|
||||
ExpressStatic(path.join(__dirname, 'dist'))
|
||||
);
|
||||
|
||||
// ACME Challenge Validation.
|
||||
app.use(['/.well-known/acme-challenge/:token'], async (
|
||||
req: ExpressRequest,
|
||||
res: ExpressResponse
|
||||
) => {
|
||||
const challenge : GreenlockChallenge | null = await GreenlockChallengeService.findOneBy({
|
||||
query: {
|
||||
key: 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('/*', (_req: ExpressRequest, res: ExpressResponse) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
});
|
||||
@@ -29,6 +58,12 @@ const init: Function = async (): Promise<void> => {
|
||||
try {
|
||||
// init the app
|
||||
await App(APP_NAME);
|
||||
|
||||
// connect to the database.
|
||||
await PostgresAppInstance.connect(
|
||||
PostgresAppInstance.getDatasourceOptions()
|
||||
);
|
||||
|
||||
} catch (err) {
|
||||
logger.error('App Init Failed:');
|
||||
logger.error(err);
|
||||
|
||||
Reference in New Issue
Block a user