-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (27 loc) · 843 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
'use strict'
const express = require('express');
const cors = require('cors');
const { createServer } = require('http');
const bodyParser = require('body-parser');
const { graphqlExpress, graphiqlExpress } = require('graphql-server-express');
const schema = require('./schema');
function run({
PORT = 3000
}) {
const app = express();
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Add an endpoint for the graphql
app.use('/graphql', graphqlExpress({ schema }));
// Add an endpoint for the graphiql ide
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql'
}));
const server = createServer(app);
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));
return server;
};
module.exports = {
run
};