-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (22 loc) · 850 Bytes
/
app.js
File metadata and controls
31 lines (22 loc) · 850 Bytes
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
const express = require('express')
const { engine } = require('express-handlebars')
const app = express()
const port = 3000
const getPassword = require('./public/model/RandomPassword')
app.engine('.hbs', engine({ extname: '.hbs' }));
app.set('view engine', '.hbs');
app.set('views', './views');
app.use(express.static('public'))
app.use(express.urlencoded({ extended: true })) //解析post數據
app.get('/', (req, res) => {
res.render('index')
})
app.post('/', (req, res) => {
const data = req.body
const length = Number(req.body.passwordLengthId)
const RandomPassWord = getPassword(length, data.Lowercase, data.Uppercase, data.Numbers, data.Symbols, data.excludeCharacters)
res.render('index', { RandomPassWord, data })
})
app.listen(port, (req, res) => {
console.log(`express server is running on http://localhost:${port}`)
})