-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
60 lines (47 loc) · 1.33 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const express = require('express')
const bodyparser = require('body-parser');
const jwt = require('express-jwt');
const { ApolloServer, gql } = require('apollo-server-express');
//const {InMemoryCache} = require('apollo-cache-inmemory');
const schema = require('./data/schema.js');
var cors = require('cors');
const PORT = 4000;
const auth = jwt({
secret: process.env.JWT_SECRET,
credentialsRequired: false,
algorithms: ['HS256']
})
const options = {
port: PORT,
bodyParserOptions: { limit: "10mb", type: "application/json"},
};
const app = express();
app.use(cors());
app.use(auth);
const server = new ApolloServer({ cors: true, schema,
context: ({ req }) => {
// Get the user token from the headers.
const token = req.headers.authorization || '';
// try to retrieve a user with the token
const user = req.user;
// add the user to the context
return { user };
},
playground:
{
endpoint:'/graphql',
settings: {
'editor.theme': 'light'
}
}
});
server.applyMiddleware({ app,
bodyParserConfig: {
limit: '100mb',
},
});
//app.use(bodyparser());
app.listen(options, () =>{
console.log("Server ready at http://localhost:${PORT}/${server.graphqlPath}");
}
);