question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work when using the "proxy" config

See original GitHub issue

Here are my configs:

{
    "proxy": "localhost:5000",
    "port": 7000
}

When I run the command without "proxy": "localhost:5000", an instance of Chrome opens on localhost:7000 as expected and everything is fine. With "proxy": "localhost:5000", it shows:

** browser-sync config **
{ injectChanges: false,
  files: [ './**/*.{html,htm,css,js}' ],
  watchOptions: { ignored: 'node_modules' },
  server: { baseDir: './', middleware: [ [Function], [Function] ] },
  logLevel: 'silent',
  proxy: 'localhost:5000',
  port: 7000 }

in the terminal and the process exits.

I tested a bit with some console.logs in lite-server.js:

console.log('executed');
browserSync.init(config, cb);
console.log('not executed');

Versions:

  • lite-server version: 2.2.0
  • nodejs version: 5.9.1
  • npm version: 3.7.3
  • OS type/version: OSX El Capitan 10.11.3

Update I gave version 2.1.0 a try and this time I got much clearer indications: Invalid config. You cannot specify both server & proxy options.

When merging the default config and the custom config, proxy and server are put together in the same set of configurations.

To temporarily fix my problem, I replaced

if (config.server.middleware) {
    config.server.middleware = _.compact(config.server.middleware);
}

by:

delete config.server;

So there are two problems:

  1. The outputs from browser-sync are not being displayed in the terminal (They are displayed in 2.1.0. but not 2.2.0). This includes Invalid config. You cannot specify both server & proxy options, but also the message telling me to add
<script id="__bs_script__">//<![CDATA[
//     document.write("<script async src='http://HOST:3000/browser-sync/browser-sync-    client.2.11.2.js'><\/script>".replace("HOST", location.hostname));
// //]]></script>

before the closing tag of the body when the application actually launches in proxy mode. 2. There is a conflict between the default server config and the proxy config.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
cgmartincommented, Apr 17, 2016

Glad it is working! BTW, there were some recent issues with proxy mode that are fixed in Browsersync 2.12.2+ (see #71).

To remove the request logging, there’s an example in the README:

Another example: To remove one of the default middlewares, such as connect-logger, you can set it’s array index to null:

module.exports = {
  server: {
    middleware: {      
      0: null     // removes default `connect-logger` middleware
    }
  }
};
2reactions
cgmartincommented, Apr 9, 2016

The proxy and server configs in browsersync are mutually exclusive. The current lite-server always uses server in the config, so browsersync fails when including proxy config.

When trying the following bs-config.json with Browsersync (without lite-server), it proxies as expected:

{ "proxy": "http://www.example.com/" }
$ browser-sync --config bs-config.json start

But as soon as you add server config, it fails with an error:

{ 
  "proxy": "http://www.example.com/",
  "server": { "baseDir": "./" } 
}
$ browser-sync --config bs-config.json start
Invalid config. You cannot specify both server & proxy options.

@maximedupre could you describe your use-case a bit more? Curious how beneficial it would be for lite-server to support proxy mode vs. using browsersync itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular-CLI proxy to backend doesn't work - Stack Overflow
NG Live Development Server is running on http://localhost:4200. ... 4 run npm start or ng serve --proxy-config proxy.conf.json.
Read more >
Proxy not working when running ng serve · Issue #4676 - GitHub
Need to run a proxy so I added --proxy-config proxy.conf.json in package.json This works if I run npm start but then I cant...
Read more >
Windows could not automatically detect network proxy settings
1. Reboot Your Computer and Router · 2. Review Proxy Settings in Windows · 3. Run the Network Adapter Troubleshooter · 4. Auto-Obtain...
Read more >
Auto configuration and auto proxy problems with Internet ...
Proxy server setup issues · Check to make sure the proxy server address is right. · Check that both Automatically detect settings and...
Read more >
How to fix "There is something wrong with the proxy server ...
Method 3: Checking your Proxy Settings · On your keyboard, press Windows Key+S. · Type “control panel” (no quotes), then hit Enter. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found