Skip to content

Commit

Permalink
move catch-all route to root
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Nov 13, 2023
1 parent ab03284 commit f3425f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
default = pkgs.mkShell {
buildInputs = with pkgs; [
nixpkgs-fmt
nodejs
gnumake
] ++ buildInputs ++ nativeBuildInputs;

Expand Down
26 changes: 14 additions & 12 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sendError } from '@/errors';
import { ReasonPhrases } from 'http-status-codes';
import { json } from 'body-parser';
import cors from 'cors';
import express from 'express';
// import {IRouter} from 'express';
import helmet from 'helmet';
import { serverErrors } from './errors';
import { httpLogger, logger, uncaughtErrorLogger } from './logger';
Expand All @@ -23,18 +23,7 @@ addOpenApiRoute(app);
app.use(httpLogger);
app.use(helmet(), json(), cors());
app.use(authMiddleware);


/**
* 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(ENV.AUTH_API_PREFIX, router);

app.use(uncaughtErrorLogger, serverErrors);

process.on('unhandledRejection', (reason) => {
Expand All @@ -59,4 +48,17 @@ 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));

// all other routes should throw 404 not found
app.use('*', (_req, res) => {
return sendError(res, 'route-not-found');
});

export { app };
6 changes: 0 additions & 6 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { sendError } from '@/errors';
import * as express from 'express';
import nocache from 'nocache';
import env from './env';
Expand Down Expand Up @@ -40,9 +39,4 @@ env(router);

router.use(oauthProviders);

// all other routes should throw 404 not found
router.use('*', (rwq, res) => {
return sendError(res, 'route-not-found');
});

export default router;

0 comments on commit f3425f7

Please sign in to comment.