1
1
import bodyParser = require( "body-parser" ) ;
2
2
import cors = require( "cors" ) ;
3
+ import dotenv = require( "dotenv" ) ;
3
4
import express = require( "express" ) ;
4
5
import { graphiqlExpress , graphqlExpress } from "graphql-server-express" ;
5
6
import helmet = require( "helmet" ) ;
6
7
7
8
import { welcomeQuery } from "./graphiQL_welcome_query" ;
8
9
import { schema } from "./schema" ;
9
10
11
+ dotenv . config ( ) ;
12
+
10
13
const app : express . Application = express ( ) ;
11
14
12
15
const helperMiddleware : express . RequestHandler [ ] = [
16
+ cors ( {
17
+ methods : [ "POST" ] ,
18
+ } ) ,
13
19
bodyParser . json ( ) ,
14
20
bodyParser . text ( { type : "application/graphql" } ) ,
15
21
( req : express . Request , res : express . Response , next : any ) => {
@@ -20,11 +26,13 @@ const helperMiddleware: express.RequestHandler[] = [
20
26
} ,
21
27
] ;
22
28
app . disable ( "x-powered-by" ) ;
23
- app . use ( cors ( ) ) ;
24
29
app . use ( "/graphql" , ...helperMiddleware , graphqlExpress ( { schema } ) ) ;
25
- app . use ( "/graphiql" , graphiqlExpress ( {
26
- endpointURL : "/graphql" ,
27
- query : welcomeQuery ,
28
- } ) ) ;
30
+ console . log ( process . env . PRODUCTION ) ;
31
+ if ( ! process . env . PRODUCTION ) {
32
+ app . use ( "/graphiql" , graphiqlExpress ( {
33
+ endpointURL : "/graphql" ,
34
+ query : welcomeQuery ,
35
+ } ) ) ;
36
+ }
29
37
30
38
export default app ;
0 commit comments