Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

配置接口代理 #1116

Closed
imindzzz opened this issue Jun 25, 2020 · 4 comments · Fixed by #1145
Closed

配置接口代理 #1116

imindzzz opened this issue Jun 25, 2020 · 4 comments · Fixed by #1145
Labels

Comments

@imindzzz
Copy link

imindzzz commented Jun 25, 2020

需求描述
我是开发web端,接口跨域了,需要配置一下prxoy。
通过configWebpackwebpack-chain实例配置config.devServer.proxy无效。

解决方案
现在我是直接改的 node_modules\@remax\cli\lib\build\web.js,临时用用。
希望能直接使用config.devServer.proxy配置

其他信息

if (designatedPort !== port) {
    output_1.default.warn(` 端口: ${designatedPort} 被占用,系统已分配另一个可用端口:${port}`);
}
output_1.default.message('🚀 启动 watch', 'blue');
output_1.default.message(`📎 http:https://localhost:${port}`, 'blue');
output_1.default.message(`📎 http:https://${address_1.default.ip()}:${port}\n`, 'blue');
const server = new webpack_dev_server_1.default(compiler, {
    publicPath: webpackOptions.output.publicPath,
    compress: true,
    hot: true,
    open: false,
    historyApiFallback: true,
    port,
    noInfo: true,
    proxy:{
        '/api': {
            target: 'https://xxxx.com',
            changeOrigin: true
            // pathRewrite: { "^/api": "" } // 匹配 api 将 api 替换为 空
        }
    }
});
@imindzzz
Copy link
Author

imindzzz commented Jun 25, 2020

const less = require('@remax/plugin-less');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = {
  one: true,
  output: 'dist/' + process.env.REMAX_PLATFORM,
  plugins: [less()],
  configWebpack({ config }) {
    // https://github.com/neutrinojs/webpack-chain
    // node_modules\@remax\cli\lib\build\web.js
    config.devServer.proxy({
      '/api': {
        target: 'https://xxxx.com',
        changeOrigin: true
        // pathRewrite: { "^/api": "" } // 匹配 api 将 api 替换为 空
      }
    });
    // 详细配置参考 copy-webpack-plugin
    config
      .plugin('copy')
      .use(CopyPlugin, [[{ from: 'src/images', to: 'images' }]]);
  }
};

config.devServer.proxy 这段应该没问题吧?

@yesmeck
Copy link
Member

yesmeck commented Jun 28, 2020

@xd199153 就是这样

@yesmeck yesmeck closed this as completed Jun 28, 2020
@imindzzz
Copy link
Author

imindzzz commented Jun 29, 2020

@xd199153 就是这样

我是说我这样配不生效~ 现在只能改node_modules里面的代码

@yesmeck yesmeck reopened this Jun 29, 2020
@yesmeck
Copy link
Member

yesmeck commented Jun 29, 2020

知道了,因为我们配了 historyApiFallback

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

Successfully merging a pull request may close this issue.

2 participants