新建样式表、客户端脚本、上传表单及upload路由

This commit is contained in:
赵鑫 2022-08-26 13:50:57 +08:00
parent 24158f15a9
commit 4857119778
4 changed files with 57 additions and 8 deletions

1
public/client.js Normal file
View File

@ -0,0 +1 @@
file_input.value = null

27
public/style.css Normal file
View File

@ -0,0 +1,27 @@
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
user-select: none;
max-width: 360px;
margin: 0 auto;
}
h1,
form {
margin: 1rem auto;
}
form {
display: grid;
grid-template-columns: auto 1fr;
gap: 1rem;
}
form button {
grid-column: span 2;
cursor: pointer;
}

View File

@ -9,11 +9,21 @@ mongoose.connect(MONGODB_URL, (error) => {
} }
}) })
const app = express() const app = express()
app.use(express.static('public'))
app.set('view engine', 'pug') app.set('view engine', 'pug')
app.get('/', async (req, res) => { app.use(express.static('public'))
res.render('index', { title: '文件分享服务器' }) app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.get('/', (req, res) => {
res.render('index')
})
app.post('/upload', (req, res) => {
res.sendStatus(201)
}) })
const server = app.listen(SERVER_PORT, SERVER_HOST, () => { const server = app.listen(SERVER_PORT, SERVER_HOST, () => {
console.info(`server is running at http://${SERVER_HOST}:${SERVER_PORT}`) console.info(`server is running at http://${SERVER_HOST}:${SERVER_PORT}`)
}) })
/**
* "bcrypt": "^5.0.1",
"md5-file": "^5.0.0",
"multer": "^1.4.5-lts.1",
*/

View File

@ -1,9 +1,20 @@
doctype html doctype html
html(lang='zh') html(lang='zh')
head head
meta(charset="UTF-8") meta(charset='UTF-8')
meta(http-equiv="X-UA-Compatible" content="IE=edge") meta(http-equiv='X-UA-Compatible' content='IE=edge')
meta(name="viewport" content="width=device-width, initial-scale=1.0") meta(name='viewport' content='width=device-width, initial-scale=1.0')
title #{title} link(rel='icon' href='/favicon.ico' type='image/x-icon')
link(rel='stylesheet' href='/style.css')
title 文件分享服务器
body body
h1 #{title} h1 文件分享服务器
if uploaded
p= uploaded
form(method='POST' action='/upload' enctype='multipart/form-data')
label(for='file_input') 文件
input(id='file_input' name='file' type='file' required)
label(for='password_input') 密码
input(id='password_input' name='password' type='password' autocomplete='off')
button(id='share_button' type='submit') 分享
script(src='/client.js')