-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (44 loc) · 1.82 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
const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const MemoryStore = require('session-memory-store')(session);
const port = process.env.PORT || 80;
const app = express();
const path = require('path');
const app_path = path.dirname(require.main.filename);
const configs = require(path.join(app_path + '/controller/configs.js'));
configs.initialize((err) => {
console.log(err);
process.exit()
});
const session_config = require(path.join(app_path + '/secrets/session.json'));
app.use(bodyParser.urlencoded({extended: false})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(express.static(__dirname + '/public'));
app.set('view engine', 'ejs');
app.use(session({
name: 'session',
secret: session_config.secret,
resave: true,
saveUninitialized: false,
maxAge: 2 * 60 * 60 * 1000, // Maximum age of 2 hours
store: new MemoryStore({
checkperiod: 10 * 60 //Check session every 10 minutes
})
}));
const auth = require(path.join(app_path + '/controller/auth'));
const pages = require(path.join(app_path + '/controller/pages'));
const posts = require(path.join(app_path + '/controller/posts'));
app.get('/', pages.index);
app.get('/register', pages.register);
app.get('/login', pages.login);
app.get('/logout', auth.isAuthenticated, pages.logout);
app.get('/dashboard', auth.isAuthenticated, pages.dashboard);
app.get('/deposit', auth.isAuthenticated, pages.deposit);
app.get('/address/balance', auth.isAuthenticated, pages.check_address_balance);
app.post('/register', posts.register);
app.post('/login', posts.login);
app.post('/deposit', auth.isAuthenticated, posts.deposit);
app.listen(port, () => {
console.log('Listening on port ' + port);
});