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

[webpack] 第2040天 在webpack中,怎么做代理? #6006

Open
haizhilin2013 opened this issue Nov 14, 2024 · 1 comment
Open

[webpack] 第2040天 在webpack中,怎么做代理? #6006

haizhilin2013 opened this issue Nov 14, 2024 · 1 comment
Labels

Comments

@haizhilin2013
Copy link
Collaborator

第2040天 在webpack中,怎么做代理?

3+1官网

我也要出题

@Elylicery
Copy link

使用webpack-dev-server的代理功能

   const path = require('path');

   module.exports = {
       // ...其他配置
       devServer: {
           contentBase: path.join(__dirname, 'dist'),
           compress: true,
           port: 9000,
           proxy: {
               '/api': {
                   target: 'http://localhost:5000', // 目标服务器地址
                   changeOrigin: true, // 对于虚拟托管的网站,这个项需要设置为true
                   pathRewrite: { '^/api': '' }, // 重写路径
               }
           }
       }
   };

在这个示例中,任何以 /api 开头的请求都会被代理到 http://localhost:5000。

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

No branches or pull requests

2 participants