2021-11-23 13:08:30 +08:00
|
|
|
/**
|
|
|
|
* 配置说明请参考文档:
|
|
|
|
* https://hongqiye.com/doc/mockm/config/option.html
|
|
|
|
* @type {import('mockm/@types/config').Config}
|
|
|
|
*/
|
2021-11-24 14:31:19 +08:00
|
|
|
module.exports = (util) => {
|
2021-11-24 20:14:43 +08:00
|
|
|
const port = 9000
|
2021-11-24 14:31:19 +08:00
|
|
|
return {
|
2021-11-24 20:14:43 +08:00
|
|
|
port,
|
2021-11-24 14:31:19 +08:00
|
|
|
api: {
|
2021-11-24 20:14:43 +08:00
|
|
|
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,
|
|
|
|
})
|
2021-11-24 14:31:19 +08:00
|
|
|
})
|
|
|
|
},
|
2021-11-23 13:08:30 +08:00
|
|
|
},
|
2021-11-24 14:31:19 +08:00
|
|
|
static: [
|
|
|
|
{ // 测试 netlify 部署
|
|
|
|
fileDir: `./dist`,
|
|
|
|
path: `/`,
|
|
|
|
},
|
|
|
|
{ // 测试 gitee/github 部署
|
|
|
|
fileDir: `./dist`,
|
|
|
|
path: `/md`,
|
2021-11-24 20:14:43 +08:00
|
|
|
},,
|
|
|
|
{ // 访问公共目录
|
|
|
|
fileDir: `./public`,
|
|
|
|
path: `/public`,
|
2021-11-24 14:31:19 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
2021-11-23 13:08:30 +08:00
|
|
|
}
|