-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (31 loc) · 1.05 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import "dotenv/config";
import express from 'express';
import http from 'http';
import cors from 'cors';
import bodyParser from 'body-parser';
import typeDefs from "./graphql/schema.js";
import resolvers from "./graphql/resolvers.js";
import dbConnect from "./dbConfig/dbConnect.js";
import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer';
const app = express();
const httpServer = http.createServer(app);
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
csrfPrevention: true,
cache: "bounded",
});
await server.start();
app.use(
'/api/countries',
cors(),
bodyParser.json(),
expressMiddleware(server)
);
dbConnect() // connect to MongoDb Atlas database
// Modified server startup
await new Promise((resolve) => httpServer.listen({ port: 4000 }, resolve));
console.log(`🚀 Server ready at http://localhost:4000/api/countries`);