diff options
| author | Hafeez | 2018-04-14 19:47:18 +0100 |
|---|---|---|
| committer | Hafeez | 2018-04-14 19:47:18 +0100 |
| commit | 71a674b70f0003e215f6d9ba5e5b94db36a83b36 (patch) | |
| tree | 4465051b949a0869f1622be155cf17cd8d73fae2 | |
| parent | returns 404 for unused routes only if logged in (diff) | |
| download | medicine-71a674b70f0003e215f6d9ba5e5b94db36a83b36.tar.gz medicine-71a674b70f0003e215f6d9ba5e5b94db36a83b36.zip | |
think i fixed something
| -rw-r--r-- | src/FileRouter.ts | 2 | ||||
| -rw-r--r-- | src/app.ts | 23 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 4ee42dc..ff0e65d 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -425,7 +425,7 @@ const getProjects: Middleware = async( }); res.locals.data = projects.map( (p: Project): ProjectFullInfo => p.fullInfo - ); + ); next(); }; @@ -111,19 +111,26 @@ class App { important: 'Endpoints start from /cs3099group-be-4/' }); }); - const errRouter: ex.Router = ex.Router(); - errRouter.get('*', (req: ex.Request, res: ex.Response): void => { - res.status(404) + //const errRouter: ex.Router = ex.Router(); + + this.express.use('/cs3099group-be-4', FileRouter); + this.express.use('/cs3099group-be-4', authRouter); + this.express.use('/', defRouter); + this.express.use((req: ex.Request, res: ex.Response, next: ex.NextFunction): void => { + console.log(res.locals) + if (Object.keys(res.locals).length === 0) { + console.log(404) + res.status(404) .json({ status: 'error', error : 'invalid_route', error_description: 'Endpoints start from /cs3099group-be-4/' }); - }); - this.express.use('/cs3099group-be-4', FileRouter); - this.express.use('/cs3099group-be-4', authRouter); - this.express.use('/', defRouter); - this.express.use('*', errRouter); + } + else { + next(); + } + }); } /** |
