-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
executable file
·45 lines (37 loc) · 1.55 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
#!/usr/bin/env node
// node app.js <port> <address> <root of filesystem>
// Address: probably "/phrasebook" or "/phrasebook-dev"
// Root: Is "E://" or "F://" on Windows, "/" on my webserver
var express = require('express');
var app = express();
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var types = require("./types");
var routes = require("./routes");
var mongoose = require('mongoose');
var MongoStore = require('connect-mongo')(session);
mongoose.connect('mongodb://localhost:27017/phrasebook');
var constants = require('./constants');
app.set('view engine', 'pug');
// Setup directories for use statically
console.log(__dirname);
app.use(`${process.argv[3]}/css`, express.static(__dirname + '/css'));
app.use(`${process.argv[3]}/js`, express.static(__dirname + '/js'));
// // app.use('/assets', express.static(__dirname + '/assets'));
app.set('views', __dirname + '/views');
// Cookies and sessions setup
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(session({
secret: constants.SECRET,
saveUninitialized: true,
resave: true,
// Store sessions in the mongo instance - persistant across Phrasebook restarts
store: new MongoStore({mongooseConnection: mongoose.connection})
}));
app.use(process.argv[3], routes.router);
app.listen(process.argv[2], "127.0.0.1", () => {
console.log(`\n${constants.APPNAME} started and listening on port ${process.argv[2]}`);
})