Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不支持restful形式api的method判断, 相同的路由没有判断method #6

Closed
carl-jin opened this issue Mar 9, 2021 · 4 comments

Comments

@carl-jin
Copy link

carl-jin commented Mar 9, 2021

问题描述

配置以下的restful api结构, 永远只会返回数组里面的第一个, 即使我用的method是 get, 它也只会返回第一个.

我看了下代码

https://github.com/anncwb/vite-plugin-mock/blob/4474a2e3c91b45bf1535ca3c93bddf6b2a79b7b7/src/createMockServer.ts#L44

应该不是我使用的不对, 程序里面好像没有判断呢

[
 {
    url: '/admin-api/api-permission',
    timeout: 1000,
    method: 'post',
    response: () => {
      return resultSuccess({});
    },
  },
  {
    url: '/admin-api/api-permission',
    timeout: 1000,
    method: 'get',
    response: ({ query }) => {
      const { page = 1, pageSize = 20 } = query;
      return resultPageSuccess(page, pageSize, apiPermissionList);
    },
  },
] as MockMethod[];
`

# 版本
v2.2.1
@carl-jin
Copy link
Author

carl-jin commented Mar 9, 2021

https://github.com/anncwb/vite-plugin-mock/blob/4474a2e3c91b45bf1535ca3c93bddf6b2a79b7b7/src/createMockServer.ts#L60

这行代码下面还是需要加一个判断, 如果method不相同就直接返回false

if(item.method.toUpperCase() !== req.method) return false;

@anncwb
Copy link
Collaborator

anncwb commented Mar 10, 2021

很好奇你为什么会写一样的api。这个在后台好像也是不能写的

@anncwb anncwb closed this as completed in efe943d Mar 10, 2021
@carl-jin
Copy link
Author

很好奇你为什么会写一样的api。这个在后台好像也是不能写的

莫非我对restful api理解的有问题 😭

@carl-jin
Copy link
Author

post /admin-api/api-permission 添加一条api权限
get '/admin-api/api-permission' 获取所有权限列表

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants