File tree Expand file tree Collapse file tree 4 files changed +43
-9
lines changed
Expand file tree Collapse file tree 4 files changed +43
-9
lines changed Original file line number Diff line number Diff line change 1- MONGODB_URI =
1+ MONGODB_URI =
2+ NODE_ENV =
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ web_modules/
7878.env.development.local
7979.env.test.local
8080.env.production.local
81+ .env.production
8182.env.local
8283
8384# parcel-bundler cache (https://parceljs.org/)
Original file line number Diff line number Diff line change 1+ service : graphql-api-with-nodejs-mongodb-lambda
2+ provider :
3+ name : aws
4+ runtime : nodejs20.x
5+ functions :
6+ graphql-api :
7+ handler : dist/lambda.handler
8+ events :
9+ - http : ANY /
10+ plugins :
11+ - serverless-dotenv-plugin
12+ custom :
13+ dotenv :
14+ path : .env.production
Original file line number Diff line number Diff line change 1+ import { ApolloServer as DevServer } from "apollo-server" ;
2+ import { ApolloServer as ProdServer } from 'apollo-server-lambda' ;
3+ import { ApolloServerPluginLandingPageGraphQLPlayground } from "apollo-server-core" ;
14import resolvers from "./graphql/resolvers" ;
25import typeDefs from "./graphql/schema" ;
6+ import dotenv from 'dotenv' ;
37
4- const { ApolloServer } = require ( 'apollo-server' ) ;
8+ dotenv . config ( ) ;
59
6- const server = new ApolloServer ( {
7- typeDefs,
8- resolvers,
9- } ) ;
10+ const isProduction = process . env . NODE_ENV === 'production' ;
11+
12+ if ( ! isProduction ) {
13+ const server = new DevServer ( {
14+ typeDefs,
15+ resolvers,
16+ } ) ;
17+
18+ server . listen ( ) . then ( ( { url } : { url : string } ) => {
19+ console . log ( `Server ready at ${ url } ` ) ;
20+ } ) ;
21+ } else {
22+ const server = new ProdServer ( {
23+ typeDefs,
24+ resolvers,
25+ introspection : true ,
26+ plugins : [ ApolloServerPluginLandingPageGraphQLPlayground ( ) ] ,
27+ } ) ;
28+
29+ exports . handler = server . createHandler ( ) ;
30+ }
1031
11- server . listen ( ) . then ( ( { url } : { url : string } ) => {
1232
13- console . log ( `Server ready at ${ url } ` ) ;
14- } ) ;
You can’t perform that action at this time.
0 commit comments