From 8d0293af5592402448769451f85ce666ed407cb4 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Fri, 20 Apr 2018 15:15:46 +0100 Subject: Finalise CORS support with package corser --- src/app.ts | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'src/app.ts') diff --git a/src/app.ts b/src/app.ts index d94011a..6a595f6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,4 +1,5 @@ import * as bodyParser from 'body-parser'; +import { cors } from './cors'; import * as ex from 'express'; import * as expressJwt from 'express-jwt'; import * as passport from 'passport'; @@ -6,7 +7,7 @@ import * as passport from 'passport'; import { default as authRouter, unauthorisedErr } from './auth'; import { logger } from './logger'; -import { RequestError, errorHandler } from './errors/errorware'; +import { errorHandler } from './errors/errorware'; import FileRouter from './FileRouter'; import { default as File } from './db/model/File'; @@ -43,7 +44,7 @@ class App { logger.debug('Constructing router'); this.logEnabled = enableLog; this.express = ex(); - this.cors(); + this.express.use(cors()); this.express.use( (req: ex.Request, res: ex.Response, next: ex.NextFunction): void => { logger.info(`Connection from ${req.ip} requesting ${req.url}`); @@ -69,23 +70,6 @@ class App { this.errorware(); } - /** - * Enables Cross-Origin for the server. - */ - public cors(): void { - this.express.use(( - req: ex.Request, res: ex.Response, next: ex.NextFunction - ): void => { - res.header('Access-Control-Allow-Origin', '*'); - res.header( - 'Access-Control-Allow-Headers', - 'Origin, X-Requested-With, Content-Type, Accept' - ); - res.header('Access-Control-Allow-Methods', '*'); - next(); - }); - } - /** * Configures regular Express middleware. */ -- cgit v1.2.1 From 09155e88a34c211dd9429a70fde432c062af77e0 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Sat, 21 Apr 2018 03:06:02 +0100 Subject: Fix many small file-handling problems --- src/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/app.ts') diff --git a/src/app.ts b/src/app.ts index 6a595f6..a6e0d27 100644 --- a/src/app.ts +++ b/src/app.ts @@ -57,7 +57,7 @@ class App { async(req: ex.Request, res: ex.Response, next: ex.NextFunction): Promise => { if (res.locals.function) { - res.locals.function.bind(res)(res.locals.data); + res.locals.function.bind(res)(await res.locals.data); } else { res.json({ status: 'success', -- cgit v1.2.1