I have installed http-server
globally.
I launch it from myDir on localhost port 8080. In myDir I have index.html
.
If I request (from the browser) http://localhost:8080/
I get index.html, which is OK.
If I request though http://localhost:8080/anything
I do not get any response from the server.
What I would like, on the contrary, is that my server always responds with index.html to any http request reaching localhost on port 8080.
Is this possible.
Thanks in advance
The open source text editor Brackets also includes a NodeJS static web server. Just open any HTML file in Brackets, press "Live Preview" and it starts a static server and opens your browser at the page. The browser will auto refresh whenever you edit and save the HTML file.
If your node server also serves this HTML page, then you can use a relative path to point to your route like this: action="/handle-form-data" . The input tag nested inside the form is used to collect user input. You have to assign a name property to your data so that you can recognize this piece of data on the server.
The http. createServer() method turns your computer into an HTTP server. The http. createServer() method creates an HTTP Server object. The HTTP Server object can listen to ports on your computer and execute a function, a requestListener, each time a request is made.
Use as specified in the documentation.
http-server --port 8080 -P http://localhost:8080?
Note the ?
at the end of the proxy URL.
To achieve what you are asking for, I recommend you live-server instead of http-server.
live-server --port=8080 --entry-file=./index.html
live-server is also providing a hot-reload but it was not one of your request
Edit: live-server is not designed to be used in production. No gzip compression for example
Edit 2: The maintainer of http-server clearly said in this comment that never, http-server will consider the SPA use-cases
Edit 3: serve seems to be a good option too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With