forked from CS3022-SE-G3/pharmacy_finder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (41 loc) · 1.27 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
const path = require('path');
const express = require('express');
const app = express();
const config = require('config');
const dotenv = require('dotenv');
const bodyParser = require('body-parser');
const session = require('express-session');
const MySQLStore = require('express-mysql-session')(session);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const options = {
host: config.get("host"),
port: config.get("port"),
user: config.get("user"),
password: config.get("password"),
database: config.get("database")
};
const sessionStore = new MySQLStore(options);
app.use(session({
store: sessionStore,
key: 'session_cookie_name',
secret: config.get("session_secret"),
resave: false,
saveUninitialized: false,
}));
dotenv.config({
path: './config/config.env'
});
// set up template engine
app.set('view engine', 'ejs');
app.set('views', 'views');
// static files
app.use(express.static(path.join(__dirname, 'public')));
require('./startup/routes')(app);
const port = process.env.PORT || 3000;
const server = app.listen(port, () => console.log(`Listening on port ${port}...`));
if (process.env.NODE_ENV=='test')
{
server.close();
}
module.exports = server;