Skip to content

Commit

Permalink
feat: support upload to local directory (doocs#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
wll8 authored Nov 24, 2021
1 parent 760e289 commit 378acb7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ yarn-error.log*
*.sw?

# mockm
httpData
httpData
public/upload/**
!public/upload/*.gitkeep
22 changes: 18 additions & 4 deletions mm.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
* @type {import('mockm/@types/config').Config}
*/
module.exports = (util) => {
const port = 9000
return {
port,
api: {
'/upload'(req, res) {
res.json({
msg: `上传成功`,
url: util.libObj.mockjs.mock(`@image`),
async '/upload'(req, res) {
const multiparty = await util.toolObj.generate.initPackge(`multiparty`)
const form = new multiparty.Form({
uploadDir: `./public/upload/`,
})
form.parse(req, (err, fields = [], files) => {
const path = files.file[0].path.replace(/\\/g, `/`)
const url = `http://127.0.0.1:${port}/${path}`
res.json({
msg: `上传成功`,
url,
})
})
},
},
Expand All @@ -21,6 +31,10 @@ module.exports = (util) => {
{ // 测试 gitee/github 部署
fileDir: `./dist`,
path: `/md`,
},,
{ // 访问公共目录
fileDir: `./public`,
path: `/public`,
},
],
}
Expand Down
Empty file added public/upload/.gitkeep
Empty file.

0 comments on commit 378acb7

Please sign in to comment.