forked from microservices-demo/front-end
-
Notifications
You must be signed in to change notification settings - Fork 241
/
server.js
58 lines (51 loc) · 1.58 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
var request = require("request")
, express = require("express")
, morgan = require("morgan")
, path = require("path")
, bodyParser = require("body-parser")
, async = require("async")
, cookieParser = require("cookie-parser")
, session = require("express-session")
, config = require("./config")
, helpers = require("./helpers")
, cart = require("./api/cart")
, catalogue = require("./api/catalogue")
, orders = require("./api/orders")
, user = require("./api/user")
, metrics = require("./api/metrics")
, app = express()
app.use(helpers.rewriteSlash);
app.use(metrics);
app.use(express.static("public"));
if(process.env.SESSION_REDIS) {
console.log('Using the redis based session manager');
app.use(session(config.session_redis));
}
else {
console.log('Using local session manager');
app.use(session(config.session));
}
app.use(bodyParser.json());
app.use(cookieParser());
app.use(helpers.sessionMiddleware);
app.use(morgan("dev", {}));
var domain = "";
process.argv.forEach(function (val, index, array) {
var arg = val.split("=");
if (arg.length > 1) {
if (arg[0] == "--domain") {
domain = arg[1];
console.log("Setting domain to:", domain);
}
}
});
/* Mount API endpoints */
app.use(cart);
app.use(catalogue);
app.use(orders);
app.use(user);
app.use(helpers.errorHandler);
var server = app.listen(process.env.PORT || 8079, function () {
var port = server.address().port;
console.log("App now running in %s mode on port %d", app.get("env"), port);
});