Comments (8)
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.
from lite-server.
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 } } };
from lite-server.
I don't seem to get alternative number 1 to work. This is my middleware:
1: proxyMiddleware('/', {
target: 'localhost:5000'
})
(My nodejs server handles both static file serving and AJAX API requests, which is why I redirect everything to localhost:5000).
When I start lite-server
, it opens the browser and gives me this message:
Error occured while trying to proxy to: localhost:3000/
In the terminal:
[HPM] PROXY ERROR: EHOSTUNREACH. localhost:3000 -> localhost:5000/
16.04.10 17:59:28 500 GET /
However, I can access localhost:5000 just fine when I try manually. Maybe I'm doing something wrong, but I haven't figured it out yet.
As for alternative number 2, since browser-sync
doesn't handle SPAs, wouldn't I lose most of the benefits?
Thank you for your help.
Update 1
Since my nodejs server already handles both static file serving and AJAX API request, I think these should be my configs:
var proxyMiddleware = require('http-proxy-middleware');
var fallbackMiddleware = require('connect-history-api-fallback');
module.exports = {
files: ['front-end/**/*.*'],
server: {
middleware: {
2: proxyMiddleware('/', {
target: 'localhost:5000'
})
}
}
};
However, it doesn't work, I still get the same error messages.
Update 2
Nevermind the update 1.
So I forgot to add "http" in "target: 'localhost:5000'". Now it woks very well!
I have a small question that isn't related to this ticket. Is there a way to remove all the request logs in the terminal?
e.g. 16.04.10 18:59:09 304 GET /assets/fankit
I passed logLevel: 'silent'
in the configs, but it seems to have no effect. I can create another ticket for that if you want.
from lite-server.
@cgmartin I was updating my initial post when you submitted your comment. Please see the update.
from lite-server.
- A fix should be possible for the lack of error logging. Good catch.
- 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.
from lite-server.
I am working on a SPA and my comprehension of lite-server
is that it works well with SPAs, as opposed to browser-sync
.
The reason I need to use a proxy is because I am developing the front and back ends at the same time. Since the (nodejs) server and lite-server
can't have the same port, I need to use the nodejs server port as a proxy to lite-server
. Essentially, I am doing this: https://gist.github.com/sogko/b53d33d4f3b40d3b4b2e
from lite-server.
Makes sense. Would either of these alternative options be viable for your use-case?
- Use
lite-server
as the static file server, and proxy via middleware to the separate nodejs back-end server on different port (see example). - Replace
lite-server
with your own server that handles both static file serving and AJAX API requests, and usebrowser-sync
in proxy mode for development. Theindex.html
fallback functionality fromlite-server
would just need to exist in your static file server.
from lite-server.
Ah right! Adding logLevel: 'silent'
actually works, but it's removing a different layer of logs. Setting the first middleware to 0 solves the problem. Thanks!
from lite-server.
Related Issues (20)
- Installation fails E429 too many Requests HOT 1
- Not listening on this port
- npm audit found vulnerabilities HOT 1
- npm is not started started script missing HOT 1
- i m trying to run npm start command but it is giving following error
- Problem with npm install HOT 2
- unable to start lite-server on wsl2 HOT 1
- Error using lite-server for create-react-app HOT 3
- The package needs to update axios to solve high severity vulnerability HOT 1
- Disable SPA handling? HOT 1
- lite-server doesn't trigger or reload the page when I save the page after adding something .
- CORS 404 OPTIONS HOT 2
- How to get Directory Listing working?
- Trying to start an html website using NPM and Lite-server HOT 2
- lite-server not installing using (npm install lite-server -g) HOT 1
- Lite-server dependecies are vulnerable (The Async package have a vulnerability)
- lite-server generating three Uncaught (in promise) errors after each reload
- Lite server disables CDN links
- Static files and api proxy HOT 1
- npm & github recommend not using: "All versions of package lite-server are vulnerable to Denial of Service"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lite-server.