forked from gitter-badger/dashboard-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (42 loc) · 1.51 KB
/
index.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
/* eslint-disable no-console */
require('dotenv/config');
const express = require('express');
const helmet = require('helmet');
// allow requests in webpack-dev-server mode (on :8080)
const cors = require('cors');
const corsOptions = {
origin: 'http://localhost:8080',
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
};
const app = express();
app.use(helmet.hidePoweredBy());
// disable IEx to open other files with same rights
app.use(helmet.ieNoOpen());
// Sets "X-Content-Type-Options: nosniff".
app.use(helmet.noSniff());
app.set('port', process.env.PORT || 3000);
app.use(express.static('dist'));
app.use('/assets', express().use(express.static('assets')));
// const graphql = _graphql.graphql;
// mutation : GraphQLHub.MutationsType,
// rootValue: req.rootValue,
// formatError: formatError,
// pretty: req.query.pretty,
let expressGraphQL = require('express-graphql');
let schema = require('./src/relay/localSchema');
const path = require('path');
app.use(cors(corsOptions));
/* eslint-disable no-unused-vars,prettier/prettier */
app.use('/graphql', expressGraphQL(req => ({
schema: schema.default,
graphiql: true,
pretty: true
})));
app.use(express.static('build'));
// doesn't work with webpack-dev-server :(
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(app.get('port'), function () {
console.log(`Express app started on http://localhost:${app.get('port')} press Ctrl-C to terminate.`);
});