-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
50 lines (42 loc) · 1.45 KB
/
Copy pathserver.js
File metadata and controls
50 lines (42 loc) · 1.45 KB
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
import express from 'express';
import cors from 'cors';
import {apolloServer} from 'apollo-server';
import Schema from './data/schema';
import Resolvers from './data/resolvers';
import {postBotMessage} from './data/GroupMeUtils';
import bodyParser from 'body-parser';
// import Mocks from './data/mocks';
const GRAPHQL_PORT = (process.env.PORT || 5000);
const WS_PORT = 8080;
const graphQLServer = express();
const corsOptions = {
origin(origin, callback){
callback(null, true);
},
credentials: true
};
graphQLServer.use('/graphql', apolloServer({
graphiql: true,
pretty: true,
schema: Schema,
resolvers: Resolvers
// mocks: Mocks,
}));
graphQLServer.all('/', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With');
res.header('Access-Control-Allow-Methods', 'GET');
return next();
});
graphQLServer.use(bodyParser.json()); // to support JSON-encoded bodies
graphQLServer.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
graphQLServer.post('/callback', function (req, res, next) {
res.send('Sending updates to server...');
postBotMessage(req);
})
graphQLServer.use(cors(corsOptions));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(
`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}/graphql`
));