Skip to content

Commit

Permalink
fix: mount oauth and healthz routes correctly when specifying AUTH_AP…
Browse files Browse the repository at this point in the history
…I_PREFIX
  • Loading branch information
dbarrosop committed Nov 7, 2023
1 parent 5663eec commit 7feffaa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 };
4 changes: 4 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const asErrors = <T>(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',
Expand Down
9 changes: 0 additions & 9 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/routes/oauth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 7feffaa

Please sign in to comment.