|
@@ -6,8 +6,10 @@ const { wrapApiData } = require(`./util.js`)
|
|
|
* https://hongqiye.com/doc/mockm/config/option.html
|
|
|
* @type {import('mockm/@types/config').Config}
|
|
|
*/
|
|
|
-module.exports = util => {
|
|
|
+module.exports = async util => {
|
|
|
+ const joi = await util.tool.generate.initPackge(`joi`)
|
|
|
return {
|
|
|
+ plugin: [util.plugin.validate, util.plugin.apiDoc],
|
|
|
guard: false,
|
|
|
port: 8100,
|
|
|
testPort: 8105,
|
|
@@ -20,7 +22,29 @@ module.exports = util => {
|
|
|
api: {
|
|
|
// 在其他文件里的 api
|
|
|
...api(util).api,
|
|
|
-
|
|
|
+ "post /api/login": util.side({
|
|
|
+ tags: [`admin`],
|
|
|
+ summary: `根据用户名获取 token`,
|
|
|
+ schema: {
|
|
|
+ body: joi
|
|
|
+ .object({
|
|
|
+ username: joi
|
|
|
+ .string()
|
|
|
+ .default(`李蕾`)
|
|
|
+ .required()
|
|
|
+ .description(`用户名`),
|
|
|
+ })
|
|
|
+ .description(`用户信息`),
|
|
|
+ },
|
|
|
+ async action(req, res) {
|
|
|
+ const { username } = req.body
|
|
|
+ res.json({
|
|
|
+ status: 200,
|
|
|
+ message: `欢迎 ${username}, 登录成功`,
|
|
|
+ token: `tokentoken`,
|
|
|
+ })
|
|
|
+ },
|
|
|
+ }),
|
|
|
// 当为基本数据类型时, 直接返回数据, 这个接口返回 {"msg":"ok"}
|
|
|
'/api/1': {msg: `ok`},
|
|
|
|