-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (32 loc) · 1.35 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
var dotenv = require('dotenv').config({ path: '/app/.env' });
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());
app.set('view engine', 'pug');
require('./config/routes')(app);
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false });
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) });
}
module.exports = app;