开发环境中的跨域代理用http-proxy-middleware+broswerSync谁用到过?

开发环境中的跨域代理用http-proxy-middleware+broswerSync+gulp谁用到过?

比如我的本地
clipboard.png
有一个3000的服务器,我希望,get
http://10.3.30.182:8999/openr...的时候,代理转发一次,因为直接请求浏览器会跨域。有没有一个完整的配置文件,不用nginx,只是Dev 环境

阅读 10.1k
4 个回答
新手上路,请多包涵

在服务器端配置CORS

  var server = {
    baseDir: baseDir,
    routes: routes
  };

  /*
   * You can add a proxy to your backend by uncommenting the line below.
   * You just have to configure a context which will we redirected and the target url.
   * Example: $http.get('/users') requests will be automatically proxified.
   *
   * For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.9.0/README.md
   */
  server.middleware = [proxyMiddleware(['/api'], {target: 'http://localhost:8080', changeOrigin: true}),
    proxyMiddleware(['/upload'], {target: 'http://localhost:8080', changeOrigin: true}),
    proxyMiddleware(['/a/login'], {target: 'http://localhost:8080', changeOrigin: true}),
    proxyMiddleware(['/a/ajaxlogin'], {target: 'http://localhost:8080', changeOrigin: true}),
    proxyMiddleware(['/a/logout'], {target: 'http://localhost:8080', changeOrigin: true})];

  browserSync.instance = browserSync.init({
    startPath: '/',
    server: server,
    browser: browser
  });

大哥,解决了吗?
求方案。
我这样设置实际不行好像。

var middlewares = proxyMiddleware(['/api'], {target: 'http://0.0.0.0:8080', changeOrigin: true});

browserSync({
  port: 8888,
  ui: {
    port: 8889
  },
  server: {
    baseDir: 'src',

    middleware: [
      middlewares,
      ...

使用我是data/baggage/getValidateCode.do
结果404

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题