Skip to content

Add a Proxy to browsersync

Alexander Yamkov edited this page Feb 10, 2017 · 12 revisions

If you have an API Server running on a different port, you may want to proxy requests from you application to your api.

You can do this by adding a middleware to browsersync. (Shortcut)

One way to do this is by installing the proxy-middleware.

npm install proxy-middleware --save-dev

Then open the file tools/config/project.config.ts.

At the top of the file you include the proxy-middleware by

const proxy = require('proxy-middleware');

As the default browsersync config is defined in tools/config/seed.config.ts we would extend it in our project specific settings (tools/config/project.config.ts):

So, you place it in the project config:

 /* Add proxy middlewar */
 this.PROXY_MIDDLEWARE = [
   require('http-proxy-middleware')({ ws: false, target: 'http://localhost:3003' })
 ];