-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (54 loc) · 1.58 KB
/
app.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
/* app.js -- application setup
* Copyright 2019 AO GUOV
*
* Contributors:
* Ianovich Sergei <[email protected]>
*
* Licensed under AGPL-3.0 or later, see LICENSE
* Stimul
*/
const fs = require('fs')
const path = require('path')
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const express = require('express')
const graphqlMiddleware = require('express-graphql')
const config = require('./config/app')
const paths = require('./config/paths')
const schema = require('./graphql/schema')
const resolvers = require('./graphql/resolvers')
const app = express()
app.set('port', config.port)
app.set('dbURL', config.dbURL)
if (config.isDevelopment) {
const config = require('./config/webpack.config')('development')
const compiler = webpack(config)
compiler.hooks.invalid.tap('invalid', () => {
console.log(new Date().toTimeString())
})
console.log(new Date().toTimeString())
app.use(
webpackDevMiddleware(compiler, {
color: true,
logLevel: 'warn'
})
)
app.use(webpackHotMiddleware(compiler))
app.use('/', express.static(path.join(__dirname, 'public')))
} else if (config.isProduction) {
if (!fs.existsSync(paths.appBuild + '/index.html')) {
console.error('stimul: web app not present in production, exiting')
process.exit(1)
}
app.use(express.static(path.join(__dirname, 'build/')))
}
app.use(
'/graphql',
graphqlMiddleware({
schema: schema,
rootValue: resolvers,
graphiql: config.isDevelopment
})
)
module.exports = app