-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
41 lines (33 loc) · 932 Bytes
/
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
import app from './app'
const express = require('express');
const app = express();
const bcrypt = require('bcrypt');
const { redirect } = require('react-router-dom');
const users = []
app.use(express.urlencoded({extended: false}))
app.post('/cadastro', async (req, res) => {
try{
const hashedPassoword = await bcrypt.hash(req.body.password, 10)
users.push({
id: Date.now().toString(),
name: req.body.username,
email: req.body.email,
password: hashedPassoword
})
res.redirect('/login');
}catch(e) {
console.log(e)
res.redirect('/cadastro')
}
})
app.get('/', (req, res) => {
res.render('App.js')
})
app.get('/login', (req, res) => {
res.render('Login.js')
})
app.get('/cadastro', (req, res) => {
res.render('Cadastro.js')
})
console.log(users);
app.listen(5000)