-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (38 loc) · 960 Bytes
/
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
const fs = require('node:fs');
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const app = express();
const validUser = {
email: '[email protected]',
password: 'changeme',
};
app.set('view engine', 'pug');
app.use(express.urlencoded());
app.use(express.static('public'));
app.use(bodyParser.json());
app.use(cookieParser());
app.get('/', (req, res) => {
console.log('cookies:', req.cookies);
res.render('index');
});
app.post('/login', (req, res) => {
if (
req.body.email === validUser.email &&
req.body.password === validUser.password
) {
res.send('yup');
} else {
res.send('nope');
}
});
app.post('/new-login', (req, res) => {
console.log('req:', req);
res.cookie('user', '1', { maxAge: 900000, httpOnly: true });
res.json({
status: 'success',
});
});
app.listen(3000, () => {
console.log('express is running on port 3000');
});