-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (50 loc) · 1.93 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
var dotenv = require('dotenv').config();
var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var app = express();
app.use(express.static(__dirname + '/public'));
app.use('/js', express.static(__dirname + '/node_modules/bootstrap/dist/js'));
app.use('/js', express.static(__dirname + '/node_modules/jquery/dist'));
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
var router = express.Router();
/*
router.use(function(request, response, next) {
if (request.path != '/preview' && (!request.cookies.gateKey || request.cookies.gateKey != process.env.GATE_KEY)) {
response.render('gate');
}
else {
next();
}
});
*/
app.use(router);
app.set('view engine', 'pug');
var dateFormat = require('dateformat');
dateFormat.i18n.monthNames = [
'Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.',
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'
];
app.locals.dateFormat = dateFormat;
require('./routes')(app);
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true });
process.env.PORT = process.env.PORT || 3333;
if (process.env.NODE_ENV == 'dev') {
var fs = require('fs');
var https = require('https');
var options = {
key: fs.readFileSync('../ssl/server.key'),
cert: fs.readFileSync('../ssl/server.crt'),
requestCert: false
};
var server = https.createServer(options, app);
server.listen(process.env.PORT, function() { console.log('https, listening on port ' + process.env.PORT) });
}
else {
app.listen(process.env.PORT, function() { console.log('http, listening on port ' + process.env.PORT) });
}