From 7feffaa6f4931d6bf899a759f617c77f867dd455 Mon Sep 17 00:00:00 2001 From: David Barroso Date: Tue, 7 Nov 2023 09:19:05 +0100 Subject: [PATCH] fix: mount oauth and healthz routes correctly when specifying AUTH_API_PREFIX --- src/app.ts | 14 ++++++++++++++ src/errors.ts | 4 ++++ src/routes/index.ts | 9 --------- src/routes/oauth/utils.ts | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/app.ts b/src/app.ts index 9dd2ffdff..d9bf05f4f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,3 +1,5 @@ +import { sendError } from '@/errors'; +import { ReasonPhrases } from 'http-status-codes'; import { json } from 'body-parser'; import cors from 'cors'; import express from 'express'; @@ -46,4 +48,16 @@ process.on('uncaughtException', (err, origin) => { process.exit(1); }); +/** + * GET /healthz + * @summary Check if the server is up and running + * @return 200 - Success - application/json + * @tags General + */ +app.get('/healthz', (_req, res) => res.json(ReasonPhrases.OK)); + +app.use('/', (_req, res) => { + return sendError(res, 'bad-request'); +}); + export { app }; diff --git a/src/errors.ts b/src/errors.ts index fa9d1da39..c189b8104 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -26,6 +26,10 @@ const asErrors = (et: { }) => et; export const ERRORS = asErrors({ + 'bad-request': { + status: StatusCodes.BAD_REQUEST, + message: 'Bad Request', + }, 'route-not-found': { status: StatusCodes.NOT_FOUND, message: 'Route not found', diff --git a/src/routes/index.ts b/src/routes/index.ts index 8ebf9a721..5a83124b7 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,6 +1,5 @@ import { sendError } from '@/errors'; import * as express from 'express'; -import { ReasonPhrases } from 'http-status-codes'; import nocache from 'nocache'; import env from './env'; import { mfaRouter } from './mfa'; @@ -16,14 +15,6 @@ import { verifyRouter } from './verify'; const router = express.Router(); router.use(nocache()); -/** - * GET /healthz - * @summary Check if the server is up and running - * @return 200 - Success - application/json - * @tags General - */ -router.get('/healthz', (_req, res) => res.json(ReasonPhrases.OK)); - /** * GET /version * @summary Get the current Hasura-auth version diff --git a/src/routes/oauth/utils.ts b/src/routes/oauth/utils.ts index b3bd8e548..36eebdebc 100644 --- a/src/routes/oauth/utils.ts +++ b/src/routes/oauth/utils.ts @@ -139,7 +139,7 @@ export const createGrantConfig = (): GrantConfig => { defaults: { origin: ENV.AUTH_SERVER_URL, - prefix: OAUTH_ROUTE, + prefix: `${ENV.AUTH_API_PREFIX}${OAUTH_ROUTE}`, transport: 'session', scope: ['email', 'profile'], response: ['tokens', 'email', 'profile', 'jwt'],