This repository has been archived by the owner on Mar 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.js
75 lines (60 loc) · 2.23 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
const port = process.env.PORT || 8000;
require('./src/clients/appinsights/AppInsightsClient').setup();
const http = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const graphqlHTTP = require('express-graphql');
const EdgesSchema = require('./src/schemas/EdgesSchema');
const MessageSchema = require('./src/schemas/MessageSchema');
const SettingsSchema = require('./src/schemas/SettingsSchema');
const TileSchema = require('./src/schemas/TilesSchema');
const resolversDirectory = process.env.ENABLE_V2 ? './src/resolvers-cassandra' : './src/resolvers';
const EdgesResolver = require(`${resolversDirectory}/Edges`);
const MessageResolver = require(`${resolversDirectory}/Messages`);
const SettingsResolver = require(`${resolversDirectory}/Settings`);
const TileResolver = require(`${resolversDirectory}/Tiles`);
const app = express();
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods', 'OPTIONS,GET,POST,PUT,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, x-ms-meta-data*,x-ms-meta-target*,x-ms-meta-abc');
// intercept OPTIONS method
if ('OPTIONS' === req.method) {
res.sendStatus(200);
} else {
next();
}
});
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use('/api/messages', graphqlHTTP({
schema: MessageSchema,
rootValue: MessageResolver,
graphiql: true
}));
app.use('/api/edges', graphqlHTTP({
schema: EdgesSchema,
rootValue: EdgesResolver,
graphiql: true
}));
app.use('/api/tiles', graphqlHTTP({
schema: TileSchema,
rootValue: TileResolver,
graphiql: true
}));
app.use('/api/settings', graphqlHTTP({
schema: SettingsSchema,
rootValue: SettingsResolver,
graphiql: true
}));
function startServer() {
console.log(`PORT: ${port}`);
const server = http.createServer(app);
server.listen(port, function () {});
}
const serverStartBlocker = process.env.ENABLE_V2
? require('./src/clients/cassandra/CassandraConnector').initialize()
: require('promise').resolve();
serverStartBlocker.then(startServer).catch(console.error);