aboutsummaryrefslogtreecommitdiff
path: root/src/app.ts
diff options
context:
space:
mode:
authorjosh97josh2018-04-20 11:53:37 +0100
committerjosh97josh2018-04-20 11:53:37 +0100
commitaf7934c3852bbde45210dd0c475817b8f20ddefc (patch)
tree39ae972ea75cfc0033161b54eb26192bec14d353 /src/app.ts
parentsmall fixes (diff)
parentreduced # of failing tests (diff)
downloadmedicine-af7934c3852bbde45210dd0c475817b8f20ddefc.tar.gz
medicine-af7934c3852bbde45210dd0c475817b8f20ddefc.zip

Merge branch ‘trh/gets’ of ssh://localhost:2222/cs3099group-be-4/project-code into trh/gets

Diffstat (limited to 'src/app.ts')
-rw-r--r--src/app.ts22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/app.ts b/src/app.ts
index 4dfeeda..d94011a 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -43,6 +43,7 @@ class App {
logger.debug('Constructing router');
this.logEnabled = enableLog;
this.express = ex();
+ this.cors();
this.express.use(
(req: ex.Request, res: ex.Response, next: ex.NextFunction): void => {
logger.info(`Connection from ${req.ip} requesting ${req.url}`);
@@ -69,6 +70,23 @@ class App {
}
/**
+ * 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.
*/
private middleware(): void {
@@ -114,8 +132,8 @@ class App {
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 => {
+ this.express.use(
+ (req: ex.Request, res: ex.Response, next: ex.NextFunction): void => {
if (Object.keys(res.locals).length === 0) {
res.status(404)
.json({