-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (41 loc) · 1.31 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
const dotenv = require('dotenv');
const express = require('express');
const exphbs = require('express-handlebars');
const nocache = require("nocache");
const bodyParser = require('body-parser');
const path = require('path');
const mongoose = require('mongoose');
const session = require('express-session');
const mongoStore = require('connect-mongo')(session);
const routes = require('./routes/routes.js');
const helper = require('./helpers/helpers.js');
const db = require('./models/db.js');
const krafts = express();
dotenv.config();
port = process.env.PORT || 3000;
hostname = process.env.HOSTNAME || 3000;
url = process.env.DB_URL;
db.connect();
krafts.set('view engine','hbs');
krafts.use(express.static(path.join(__dirname, '/public')));
krafts.use(express.json());
krafts.use(express.urlencoded({extended:true}));
krafts.engine('hbs',exphbs({
defaultLayout: 'main',
extname:'.hbs',
helpers: helper})
);
krafts.use(nocache());
krafts.use(session({
secret: process.env.session_secret,
resave: false,
saveUninitialized: false,
store: new mongoStore({mongooseConnection: mongoose.connection})
}));
krafts.use('/',routes);
krafts.listen(port, hostname, function() {
console.log('Server is running at: ');
console.log('http://' + hostname + ':' + port);
});
/* For unit testing of REST API */
module.exports = krafts;