Handle unknown routes
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
},
{
"description": "Localhost - Dev - Tenant Management",
- "url": "http://localhost/v1/api"
+ "url": "http://localhost:8080/v1/api"
},
{
"description": "Localhost - Dev - Auth Management",
- "url": "http://localhost/v1/auth"
+ "url": "http://localhost:8080/v1/auth"
}
],
"info": {
},
"/signin": {
"post": {
- "description": "Login",
+ "description": "Sign in",
"requestBody": {
"content": {
"application/json": {

MODIFY
src/server/rest/v1/router/GlobalRouter.ts
src/server/rest/v1/router/GlobalRouter.ts
+import express, { NextFunction, Request, Response } from 'express';
+
import AuthRouter from './auth/AuthRouter';
import AuthService from '../service/AuthService';
+import { StatusCodes } from 'http-status-codes';
import SwaggerRouter from './doc/SwaggerRouter';
import TenantRouter from './api/TenantRouter';
import UtilRouter from './util/UtilRouter';
-import express from 'express';
export default class GlobalRouter {
private router: express.Router;
@@ -17,6 +19,7 @@ export default class GlobalRouter {
this.buildRouteAPI();
this.buildRouteUtils();
this.buildRouteDocs();
+ this.buildUnknownRoute();
return this.router;
}
@@ -37,4 +40,13 @@ export default class GlobalRouter {
protected buildRouteDocs(): void {
this.router.use('/docs', new SwaggerRouter().buildRoutes());
}
+
+ protected buildUnknownRoute(): void {
+ this.router.use('*', (req: Request, res: Response, next: NextFunction) => {
+ if (!res.headersSent) {
+ res.sendStatus(StatusCodes.NOT_FOUND);
+ next();
+ }
+ });
+ }
}

Handle unknown routes