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

希望支持配置response headers解决跨域问题 #132

Open
bloodlust opened this issue Mar 13, 2024 · 2 comments
Open

希望支持配置response headers解决跨域问题 #132

bloodlust opened this issue Mar 13, 2024 · 2 comments

Comments

@bloodlust
Copy link

      if (isFunction(rawResponse)) {
        await rawResponse.bind(self)(req, res);
      } else {
        const body = await parseJson(req);
        res.setHeader("Content-Type", "application/json");
        res.statusCode = statusCode || 200;
        const mockResponse = isFunction(response) ? response.bind(self)({url: req.url, body, query, headers: req.headers}) : response;
        res.end(JSON.stringify(_mockjs2.default.mock(mockResponse)));
      }

我们公司的项目,有一批mock的api接口比较通用,可以给多个产品提供服务。

但,JSON 请求时,无法修改headers,导致不能解决跨域问题。

我们公司临时解决方案是dockerfile里用命令修改 node_modules/vite-plugin-mock/dist/index.js 文件:

res.setHeader("Access-Control-Allow-Origin", "*");

希望能够支持配置 headers

@yanhao98
Copy link

临时修改,你可以用patch-package也行。

@So-For
Copy link

So-For commented Apr 8, 2024

有类型需求,希望增加允许跨域设置

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

3 participants