-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
68 lines (53 loc) · 1.58 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
var express = require("express");
var morgan = require("morgan");
var path = require("path");
var app = express();
var bodyParser = require("body-parser");
var config = require("./config");
var LED = require("./server/leds");
var leds = new LED();
leds.init(config.ledCount, config.ledOffset, config.enableSPI);
app.use(express.static(path.join(__dirname, "/public")));
app.use(morgan("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var port = config.APP_PORT || 4000;
app.listen(port);
console.log("LED Controller Listening On Port: " + port);
console.log('Node Env:', process.env.NODE_ENV)
if (process.env.NODE_ENV !== 'production') {
var webpack = require("webpack");
var webpackConfig = require("./webpack.config");
var compiler = webpack(webpackConfig);
app.use(
require("webpack-dev-middleware")(compiler, {
logLevel: "warn",
publicPath: webpackConfig.output.publicPath
})
);
app.use(
require("webpack-hot-middleware")(compiler, {
log: console.log,
path: "/__webpack_hmr",
heartbeat: 10 * 1000
})
);
}
var router = express.Router();
require("./server/routes")(router, leds);
app.use("/api", router);
app.use(function (req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "http://localhost:" + port);
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, OPTIONS, PUT, PATCH, DELETE"
);
res.setHeader(
"Access-Control-Allow-Headers",
"X-Requested-With,content-type"
);
next();
});
app.get("/", function (req, res) {
res.sendfile("./public/index.html");
});