-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (43 loc) · 1.53 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
require('dotenv').config()
// require("babel-core/register");
// require("babel-polyfill");
var express = require('express')
var exphbs = require('express-handlebars')
var cookieParser = require('cookie-parser')
var favicon = require('serve-favicon')
var path = require('path')
var fs = require('fs')
var app = express()
const serverApp = process.env["serverApp"] || "coreApi"
app.disable('x-powered-by');
const viewsRootPath = fs.existsSync(path.join(__dirname, '/views')) ? path.join(__dirname, '/views') : path.join(__dirname, `/${serverApp}/views`)
app.engine('handlebars', exphbs({
defaultLayout: 'main',
layoutsDir: path.join(viewsRootPath, `/layouts`),
partialsDir: viewsRootPath,
}))
app.set('view engine', 'handlebars')
app.set('views', viewsRootPath);
app.use(cookieParser())
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
if (process.argv.filter(function(x) {return x === "webpack"}).length > 0) {
var config = require('./webpack.config')(process.env);
var webpack = require('webpack');
var webpackMiddleware = require("webpack-dev-middleware");
var compiler = webpack(config)
app.use(webpackMiddleware(compiler, {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
}))
app.use(require("webpack-hot-middleware")(compiler));
}
const main = require(`./build/${serverApp}/main`)
main.default(app)
const port = parseInt(process.env["port"] || "3000")
app.listen(port, function (err, result) {
if (err) {
return console.log(err);
}
console.log(`Listening at http://*:${port}/`);
});