How to properly configure Browsersync for a proxy server

I am struggling with proper Browsercync configuration (and maybe some middleware?).

My config is like:

local.example.com

its local address is configured via /etc/hosts

.

devel.example.com

It is our company that develops the environment (backend).

staging.example.com

it is our intermediate environment for our company.

As a UI developer, I want to use my local code, but I am working from one of the backend systems.

I am using gulp

to build my project etc. He also has the task of launching browser-sync

and monitoring file changes. But of course there are now issues with cookie domains coming from the backend. The CSRF corn domain is set by the browser to the backend being used.

I tried:

  • To use http-proxy-middleware

    configuration middleware :

    server: {
      baseDir: './build',
      middleware: [
        proxyMiddleware('/api', {
          target: 'http://devel.example.com',
          changeOrigin: true,
        })
      ]
    ]
    
          

    But the problem I have is that it does the opaque redirects that are visible in the browser console. I thought it would work like this: the proxy will mask these requests in the browser, think that all requests and responses are coming from local.example.com

    . But it doesn't seem to work (or maybe I didn't configure it well).

    Also the big problem with this solution is that it somehow changes my HTTP requests POST

    to GET

    (WTF ?!).

  • Use build function in browser-sync

    proxy

    . I've used an option proxy

    with an option in a lot of tutorials server

    , but it doesn't seem to work anymore. So I tried to use it with the serveStatic

    following:

    serveStatic: ['./build'],
    proxy: {
      target: 'devel.example.com',
      cookies: {
        stripDomain: false
      }
    }
    
          

    But that doesn't work at all ...

I would really like some help with this topic.

thank

+3


source to share





All Articles