webpack-dev-server 代理:带有通配符的上下文 [英] webpack-dev-server proxy: context with wildcard

查看:95
本文介绍了webpack-dev-server 代理:带有通配符的上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将/v1/* 代理到

解决方案

更新:感谢@chimurai,设置 changeOrigin: true 对使其工作很重要.

下面 webpack-dev-server 将所有代理配置传递给 http-proxy-middleware,来自 文档.很明显,您想要的用例实际上是通过 /v1/** 路径实现的:

devServer: {historyApiFallBack: 真,//进度:真,热:真的,内联:真实,//https: 真,端口:8081,contentBase: path.resolve(__dirname, 'public'),代理人: {'/v1/**':{目标:'http://api.in.uprintf.com',安全:假,更改来源:true}}},

I want to proxy /v1/* to http://myserver.com, and here is my script

devServer: {
  historyApiFallBack: true,
  // progress: true,
  hot: true,
  inline: true,
  // https: true,
  port: 8081,
  contentBase: path.resolve(__dirname, 'public'),
  proxy: {
    '/v1/*': {
      target: 'http://api.in.uprintf.com',
      secure: false
      // changeOrigin: true
    },
  },
},

but it doesn't work,

解决方案

Update: thanks to @chimurai, setting changeOrigin: true is important to make it work.

Underneath webpack-dev-server passes all the proxy configuration to http-proxy-middleware, from the documentation. It's clear the use case you want is actually achieved with /v1/** path:

devServer: {
   historyApiFallBack: true,
   // progress: true,
   hot: true,
   inline: true,
   // https: true,
   port: 8081,
   contentBase: path.resolve(__dirname, 'public'),
   proxy: {
     '/v1/**': {
       target: 'http://api.in.uprintf.com',
       secure: false,
       changeOrigin: true
     }
   }
 },

这篇关于webpack-dev-server 代理:带有通配符的上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆