forked from pdx-urban-dash/pdx-urban-dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (37 loc) · 1.12 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
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const { ApolloServer } = require('apollo-server-express');
const graphSchema = require('./src/graphAPI/schema');
const { GoogleSheetsAPI } = require('./src/graphAPI/googleSheetsAPI');
const app = express();
const port = process.env.PORT;
const graphQlServer = new ApolloServer({
typeDefs: graphSchema.typeDef,
resolvers: graphSchema.resolvers,
dataSources: () => ({
googleSheetsAPI: new GoogleSheetsAPI(),
}),
mocks: false,
context: {},
});
app.use(express.static(path.join(__dirname, 'build')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
graphQlServer.applyMiddleware({
app,
playground: {
endpoint: `http://localhost:${port}/graphql`,
settings: {
'editor.theme': 'light',
},
},
path: '/graphql',
});
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(port, () => {
console.log(`📈 Listening on port ${port}`);
console.log(`🚀 serving graphql API at http://localhost:${port}/graphql`);
});