-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (34 loc) · 1.06 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
var http = require('http');
var path = require('path');
var express = require('express');
var bodyParser = require('body-parser');
const {
graphqlExpress,
graphiqlExpress
} = require('apollo-server-express');
const schema = require('./schema');
const connectMongo = require('./myMongo');
const start = async() => {
var app = express();
var server = http.createServer(app);
app.use(bodyParser.json());
app.use(express.static(path.resolve(__dirname, 'views/dist')));
const mongo = await connectMongo();
app.use('/graphql', bodyParser.json(), graphqlExpress({
context: {
mongo
},
schema
}));
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
app.get('/*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'views/dist/index.html'));
})
server.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0", () => {
var addr = server.address();
console.log("Server listening at port", addr.address + ":" + addr.port);
})
};
start();