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

如何配置接口代理 proxy 可以提供一下示例么? #1750

Closed
Sunbridger opened this issue Jan 13, 2025 · 2 comments
Closed

如何配置接口代理 proxy 可以提供一下示例么? #1750

Sunbridger opened this issue Jan 13, 2025 · 2 comments

Comments

@Sunbridger
Copy link

No description provided.

Copy link

要在 umijs/mako 中配置接口代理(proxy),可以按照以下步骤进行:

  1. 安装 Mako
    首先,通过 npm 或 pnpm 安装 Mako。

    $ npm i @umijs/mako -D
  2. 配置 Mako
    在你的项目配置文件中添加 mako 字段。你可以使用以下命令来设置:

    $ npx umi config set mako {}

    这将在 .umirc.tsconfig/config.ts 中生成以下配置:

    export default {
    +   mako: {},
    };
  3. 运行 Umi 项目
    现在,你可以使用 Mako 来运行 Umi 项目。

    $ umi build
  4. 配置代理
    .umirc.tsconfig/config.ts 中,你可以添加 proxy 配置来设置接口代理。例如:

    export default {
      proxy: {
        '/api': {
          target: 'http://your-api-server.com',
          changeOrigin: true,
          pathRewrite: { '^/api': '' },
        },
      },
    };

这样配置后,所有以 /api 开头的请求都会被代理到 http://your-api-server.com,并且路径中的 /api 会被移除。

希望这个示例能帮助你配置接口代理。如果有其他问题,请随时问我。

🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.

@sorrycc
Copy link
Member

sorrycc commented Jan 13, 2025

proxy 和 mako 无关,不过你可以参考 bundler-mako 的方式实现,见 https://github.com/umijs/mako/blob/master/packages/bundler-mako/index.js#L108-L136

@sorrycc sorrycc closed this as completed Jan 13, 2025
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