-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (36 loc) · 1021 Bytes
/
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
38
39
40
41
42
43
44
45
46
47
48
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
const cors = require('cors');
const dotEnv = require('dotenv');
const resolvers = require('./resolvers');
const typeDefs = require('./typeDefs');
const { connection } = require('./database/util');
const { verifyUser } = require('./helper/context');
// set env variables
dotEnv.config();
const app = express();
//db connectivity
connection();
// cors
app.use(cors());
// body parser middleware
app.use(express.json());
const apolloServer = new ApolloServer({
typeDefs,
resolvers,
context: async ({ req }) => {
await verifyUser(req);
return {
email: req.email,
userId: req.loggedInUserId,
}
}
});
apolloServer.applyMiddleware({ app, path: '/graphql' });
const PORT = process.env.PORT || 3000;
app.use('/', (req, res, next) => {
res.send({message : 'Hello'});
})
app.listen(PORT, () => {
console.log(`Server listening on PORT: ${PORT}`);
})