forked from node-red/flow-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (52 loc) · 1.67 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
var path = require("path");
var mustache = require('mustache');
var express = require('express');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var serveStatic = require('serve-static');
var settings = require('./config');
var templates = require("./lib/templates");
var events = require("./lib/events");
var app = express();
app.use(cookieParser());
if (process.env.FLOW_ENV == "PRODUCTION") {
app.use(session({
store: new MongoStore({
url: settings.mongo.url,
touchAfter: 24 * 3600
}),
key: settings.session.key,
secret: settings.session.secret,
saveUninitialized: false,
resave: false
}));
} else {
app.use(session({
key: settings.session.key,
secret: settings.session.secret,
saveUninitialized: false,
resave: false
}));
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use("/",serveStatic(path.join(__dirname,'public')));
app.use(require("./routes/index"));
app.use(require("./routes/auth"));
app.use(require("./routes/flows"));
app.use(require("./routes/nodes"));
app.use(require("./routes/admin"));
app.use(require("./routes/api"));
app.use(function(req, res) {
res.status(404).send(mustache.render(templates['404'],{sessionuser:req.session.user},templates.partials));
});
app.listen(settings.port||20982);
console.log('Listening on port',settings.port||20982);
if (process.env.FLOW_ENV === 'PRODUCTION') {
events.add({
action:"started",
message:"Flow Library app started"
});
}