-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (61 loc) · 2.21 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import express from 'express'
import bodyParser from 'body-parser'
import path from 'path'
import cors from 'cors'
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'
import { makeExecutableSchema } from 'graphql-tools'
import { fileLoader, mergeResolvers, mergeTypes } from 'merge-graphql-schemas'
import Controllers from './controllers'
// import prettyjson from 'prettyjson'
import models from './models'
import config from './config'
const typeDefs = mergeTypes(fileLoader(path.join(__dirname, './schema')))
const resolvers = mergeResolvers(fileLoader(path.join(__dirname, './resolvers')))
const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
const app = express()
/**
* app setup
*/
// bodyParser is needed just for POST.
app.use(bodyParser.json({ limit: '5mb' }))
app.use(bodyParser.urlencoded({ extended: true, limit: '5mb', parameterLimit: 100000 }))
// Check if in developer mode
if (process.env.node_env === 'development') {
console.log('Development Mode: true')
}
console.log('Drop Database: ', config.dbRefresh)
// Server Root
app.use(config.graphqlEndpoint, cors(), bodyParser.json(), graphqlExpress({
schema,
context: {
models,
},
}))
app.use('/graphiql', graphiqlExpress({ endpointURL: config.graphqlEndpoint }))
/**
* Non GraphQL Endpoints
*/
// Home
app.get('/', Controllers.home)
// TEMS INITIALIZATION message handler
app.post('/TEST_CELL/:testerName/INITIALIZATION', Controllers.initialization)
// TEMS Maintenance Handler
// This controller is different. Uses the functional programming I was learning.
app.post('/TEST_CELL/:testerName/MAINTENANCE', Controllers.maintenance)
// TEMS CONFIGURATION message handler
app.post('/TEST_CELL/:testerName/CONFIGURATION', Controllers.configuration)
// TEMS STATUS message handler
app.post('/TEST_CELL/:testerName/STATUS', Controllers.status)
/**
* Server Startup
* if force is true, the database will be empty upon server start
*/
models.sequelize.sync({ force: config.dbRefresh }).then(() => {
// Start server
app.listen(config.PORT, config.host)
console.log(`Graphql Endpoint: ${config.graphqlHost}:${config.PORT}${config.graphqlEndpoint}`)
console.log(`App is listening at host ${config.host} port ${config.PORT}`)
})