-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (37 loc) · 1.03 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
const settings = require('./settings');
const express = require('express');
const app = express();
let userData = null;
app.use(express.urlencoded({extended: false}));
app.use('/data', (req, resp, next) => {
if(userData.firstname == '' || userData.lastname == ''){
resp.send(`<h3>Нет данных пользователя</h3>`);
}
next();
});
app.get('/', (req, resp) => {
resp.redirect('/home');
});
app.get('/home', (req, resp) => {
resp.sendFile(__dirname + '/home.html');
});
app.post('/home', (req, resp) => {
resp.redirect('/add');
});
app.get('/data', (req, resp) => {
resp.sendFile(__dirname + '/data.html');
});
app.post('/data', (req,resp) => {
var serializedUser = JSON.stringify(userData);
resp.send(serializedUser);
});
app.get('/add', (req, resp) => {
resp.sendFile(__dirname + '/add.html');
});
app.post('/add', (req, resp) => {
userData = req.body;
resp.redirect('/data');
});
app.listen(settings.port, settings.host, () => {
console.log('Success start!!!');
});