rumkin / plant

🌳 JS web server charged with WebAPI and neat HTTP2 support
https://npmjs.com/package/@plant/plant
80 stars 6 forks source link

Creating JS web server without Node.js #38

Closed Choons closed 3 years ago

Choons commented 3 years ago

Hi, I found this article earlier today: https://dev.to/rumkin/how-to-create-js-webserver-without-node-js-1hic

that talks about running a web server in the browser without Node, but after several hours trying to work with the examples and read the code, it seems like Node is always necessary?

I am trying to launch a web page locally from a self-extracting archive and was hoping to find some kind of micro http server that could be embedded and started with it at the same time WITHOUT Node having to be installed.. That way I could get around the absurd CORS restrictions on accessing local assets. Plant sounded like the perfect solution, but I haven't been able to make it work.

I find it ridiculous that not even a favicon will load locally without a server running. I understand the CORS concept, but think it should accommodate local use. Is this something I can use Plant to do?

rumkin commented 3 years ago

Hi, thanks for being interested in Plant. AFAIK according to web browsers limitations it is impossible to do what you want. You can use Plant to develop some logic and make it work in a browser and then run the code into Node.js and it should work if you use compatible classes and syntax. So if you want to listen incoming connections or host local assets, then you still need to run some kind of a server.

I have some ideas of how to create a webserver logic working in a browser and almost without a real server. But it's still in development and is not what Plant is about to do.

Choons commented 3 years ago

Hi, thank you for the prompt reply! Yes, that notion of a server running in the browser is exactly what I am looking for. I mean Node works fabulously running on its own copy of the V8 engine, so why isn't it possible to do the same right there in the browser's V8 engine for local web apps? It seems ridiculous to me that an Electron app has to redundantly duplicate all that Chrome browser code when it's right there installed like a perfect virtual machine already. And it's baffling to me why browsers allow easier access to unknown machines all over the world than they do to the machine they are running on. I understand all the security arguments, but come on, browsers should be more useful running local stuff.

I am experimenting with how far I can take running a web app locally in the browser without a server, launched by a double click on the index.html file, or by using an SFX to launch the index.html, so it's running under the simple file:/// protocol. I intend to write an article about it if it is interesting enough. I'll post back to let you know if I do.