Comments (1)
has a good discussion on this topic and the question mark is really important here and will solve it.
http-server --port 8080 -P http://localhost:8080?
Do you think its worth having a section devoted to running a SPA server with choo?
I also want to point out that I use something like in my package.json
"start": "http-server ./web -o -c-1 -p 8080 --proxy http://localhost:8080?"
And that if you do something like this, make sure you point your src
or other local lookups to /
first otherwise the proxy would load src="bundle.js"
to the proxied path.
<script src="/bundle.js"></script>
Also, it is common to have a BE resource that you want proxied and I want to share how I did this for comment or to help others.
const http = require("http"),
httpProxy = require("http-proxy");
const proxy = httpProxy.createProxyServer();
const server = http.createServer(function (req, res) {
if (req.url.indexOf("/api/") > -1) {
proxy.web(req, res, { target: "http://127.0.0.1:5150" });
} else {
proxy.web(req, res, { target: "http://localhost:8080" });
}
});
server.listen(5050);
Now your proxy sits behind a router where all requests go into your http/s server on 5050 then requests either go to http-server
or they are marked as back-end with /api/
. When requests go to http-server
, the catch-all redirect works for your SPA. The only thing you have to manage is the cookie path in your set headers if you use cookies in your Backend node server and you rewrite the url after the if statement to check for /api/
Now you have both SPA with catchall redirect and BE proxying logic with http-proxy. The author of http-server don't really have a clear focus on serving SPA needs so I think this method might be fill in some needed gaps.
from choo.
Related Issues (20)
- Flicker on route change + window scroll in Safari HOT 2
- Redirects do not work HOT 3
- Page freeze in Safari when navigating using trackpad swipe HOT 3
- Is choo abandoned / no longer maintained? HOT 4
- HTML5 video autoplay in chrome HOT 9
- Running Router On a Specific Path with Hash Routing HOT 3
- Could not query selector id with hypen HOT 4
- Magic in the emitter callback? HOT 4
- v7.0.0 HOT 7
- Is it possible to use choojs with es import syntax? HOT 2
- Can I pass a rootNode to `nanohref`? HOT 5
- New feature: Async route support HOT 1
- [domain] ssl-cert expired HOT 6
- Experimenting with custom elements
- Route handler return value HOT 3
- What are the precise set of rewrite rules so that if a user specifies app.mount(<PATH>, component) they can retrieve that in the URL?
- Wrong return type for `mount`
- SSL_CTX_use_certificate:ee key too small
- Project abandoned? HOT 7
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 choo.