-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
119 lines (82 loc) · 2.48 KB
/
server.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var express = require('express');
var session = require('express-session');
var SessionStore = require('express-mysql-session');
var DataBase = require('./server/db/database.js');
var cookieParser = require('cookie-parser')
var bodyParser = require('body-parser');
var Binary = require('./app/binary.js');
var async = require('async');
var binary = new Binary();
var database = new DataBase();
//123456789
var app = express();
var options = {
host: 'localhost',
user: 'root',
password: '',
database: 'save_money',
table: 'sessions'
}
//sadfasdfasdf
var router = express.Router();
var http = require('http').Server(app);
app.use(express.static('node_modules'));
app.use(express.static('app'));
app.use(express.static('css'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(cookieParser());
var expiryDate = new Date( Date.now() + 60 * 60 * 1000 ); // 1 hour
app.use(session({
key: 'save_money',
secret: 'SaveMoney20-06',
saveUninitialized: false,
resave: false,
store: new SessionStore(options),
cookie: {
httpOnly: true,
domain: 'localhost',
expires: expiryDate
}
}))
//=======Start server=============
http.listen(8080,function () {});
//================================
//======Connect to data base=======
try {
database.connect();
}catch (exp){
console.error(exp);
}
//=================================
//=============Send files===================
app.get('/',function (req,res) {
res.sendFile (__dirname+'/index.html');
});
app.get('/app/bundle.js',function (req,res) {
res.sendFile (__dirname+'/app/bundle.js')
});
app.get('/firebase-messaging-sw.js',function (req,res) {
res.sendFile (__dirname+'/firebase-messaging-sw.js')
});
app.get('/username',function (req,res) {
if(req.session.login){
res.send({
login : req.session.login
})
}else res.send('undefined')
});
app.get('*', function(req, res){
res.sendfile(__dirname+'/server/404page.html', 404);
});
//=========================================
//==========Handlers of requests===============
//registration
app.post('/cipher',require('./server/routes/cipher').post);
app.post('/registration',require('./server/routes/registration').post);
//sing up
app.post('/salt',require('./server/routes/salt').post);
app.post('/login',require('./server/routes/login').post);
//sing out
app.post('/singout',require('./server/routes/singout').post);
//===============================