-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (43 loc) · 1.57 KB
/
app.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
const express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path');
const session = require('express-session');
const app = express();
const mysql = require('mysql');
const bodyParser = require("body-parser");
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'test'
});
connection.connect();
global.db = connection;
app.set('port', process.env.PORT || 8080);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/public', express.static(__dirname + '/public/'));
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: {maxAge: 60000}
}));
app.get('/', routes.index);//call for main index page
app.get('/signup', user.signup);//call for signup page
app.post('/signup', user.signup);//call for signup post
app.get('/login', routes.index);//call for login page
app.post('/login', user.login);//call for login post
app.get('/home/dashboard', user.dashboard);//call for dashboard page after login
app.get('/home/logout', user.logout);//call for logout
app.get('/home/profile', user.profile);//to render users profile
app.get('/home/xray', user.xray);//to render Xray page
app.post('/home/xray', user.xray);//to post status Xray page
app.listen(8080, () => {
console.log('server running on http://localhost:8080');
});