Browse Source

refactor(server): Simplify cors implementation

Michael Bromley 7 years ago
parent
commit
7050c2002e
2 changed files with 2 additions and 16 deletions
  1. 1 15
      server/src/app.module.ts
  2. 1 1
      server/src/main.ts

+ 1 - 15
server/src/app.module.ts

@@ -67,21 +67,7 @@ export class AppModule implements NestModule {
                 }),
             )
             .forRoutes('/graphiql')
-            .apply([
-                (req, res, next) => {
-                    res.header('Access-Control-Allow-Origin', '*');
-                    res.header(
-                        'Access-Control-Allow-Headers',
-                        'Content-Type, Authorization, Content-Length, X-Requested-With',
-                    );
-                    if (req.method === 'OPTIONS') {
-                        res.sendStatus(200);
-                    } else {
-                        next();
-                    }
-                },
-                graphqlExpress(req => ({ schema, rootValue: req })),
-            ])
+            .apply(graphqlExpress(req => ({ schema, rootValue: req })))
             .forRoutes('/graphql');
     }
 

+ 1 - 1
server/src/main.ts

@@ -2,7 +2,7 @@ import { NestFactory } from '@nestjs/core';
 import { AppModule } from './app.module';
 
 async function bootstrap() {
-    const app = await NestFactory.create(AppModule);
+    const app = await NestFactory.create(AppModule, { cors: true });
     await app.listen(3000);
 }
 // tslint:disable:no-floating-promises