7 ms·
Simple Web Server
- bsimpson 2y agoIf you globally install the npm module dhost, you can run it from any directory (`dhost`) to start a webserver there. Python 2 had a similar function (`python -m SimpleHTTPServer`). I know there's a Python 3 equivalent, but I don't have it memorized.
- bondant 2y agopython3 -m http.server
- Imustaskforhelp 2y agoI also use this! like I wanted a backup of my device once to my phones when my system was messed up. and I used this. Though I would prefer a way to keep it downloading from where it left because this method ISNT reliable for 40 gigs transfer I am also wondering about this comment in the gist which was linked (gist.github.com/willurd/5720255) by olejorgenb which is Limiting request to a certain interface (eg.: do not allow request from the network) python -m http.server --bind 127.0.0.1 Like what does that really do? Maybe its also nice, IDK?
- bsimpson 2y ago127.0.0.1 means "self" in IP. Presumably that means that it if you browse to your IP address from your computer it will work, but from your phone it will not. I usually do the opposite - 0.0.0.0 - which allows connections from any device.
- kzahel 2y agoI wrote the original version of this "simple web server" app (https://chromewebstore.google.com/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb https://chromewebstore.google.com/detail/web-server-for-chro...) because the built-in python http server is a bit buggy. It would hang on some connections when loading a webpage with a lot of small assets. I was surprised how many people found it useful. More so when Chrome web apps were supported on other platforms (mac/linux/windows).
- vyrotek 2y agoI use serve https://www.npmjs.com/package/serve https://www.npmjs.com/package/serve
- bangaladore 2y agoShould support self-signed HTTPs ideally. IIRC there a quite a few (some?) web features that do not function unless the page is served over HTTPs. That would certainly make this more useful than `python3 -m http.server`.
- zamadatix 2y agoIt does. It also includes a dozen other things beyond what that one liner would do. Keep in mind, if it fits with what you're trying to test/how you're trying to develop, just doing things on http://localhost http://localhost will be treated as a secure origin in most browsers these days. There does seem to be a weird limitation that you can't enable both HTTP and HTTPS on the same port for some reason. That should be easy enough to code a fix for though.
- bangaladore 2y ago> HTTP and HTTPS on the same port Do any real web servers support this? Its the same transport (TCP assuming something like HTTP 1.1) and trying to mix HTTP and HTTPS seems like a difficult thing to do correctly and securely.
- p4bl0 2y agoTheoretically it would be feasible with something like STARTTLS that allows to upgrade a connection (part of SMTP and maybe IMAP) but browsers do not support this as it is not part of standard HTTP.
- ekr____ 2y agoIt actually is part of standard HTTP [0], just not part of commonly implemented HTTP. The basic difference between SMTP and HTTP in this context is that email addresses do not contain enough information for the client to know whether it should be expecting encrypted transport or not (hence MTA-STS and SMTP/DANE [1]), so you need to negotiate it with STARTTLS or the like, whereas the https URL scheme tells the client to expect TLS, so there is no need to negotiate, you can just start in with the TLS ClientHello. In general, it would be inadvisable at this point to try to switch hit between HTTP and HTTPS based on the initial packets from the client, because then you would need to ensure that there was no ambiguity. We use this trick to multiplex DTLS/SRTP/STUN and it's somewhat tricky to get right [2] and places limitations on what code points you can assign later. If you wanted to port multiplex, it would be better to do something like HTTP Upgrade, but at this point port 443 is so entrenched, that it's hard to see people changing. [0] https://www.rfc-editor.org/rfc/rfc7230#section-6.7 https://www.rfc-editor.org/rfc/rfc7230#section-6.7. [1] https://datatracker.ietf.org/doc/html/rfc8461 https://datatracker.ietf.org/doc/html/rfc8461 https://datatracker.ietf.org/doc/html/rfc7672 https://datatracker.ietf.org/doc/html/rfc7672 [2] https://datatracker.ietf.org/doc/html/rfc7983 https://datatracker.ietf.org/doc/html/rfc7983
- dpz 2y agohttps://gist.github.com/willurd/5720255 https://gist.github.com/willurd/5720255
- dark-star 2y agocd /some/dir && python -m http.server 8080
- __fst__ 2y agopython3 -m http.server -d /path/to/dir
- rad_gruchalski 2y agoDon’t forget 8080. http.server binds on port 8000 by default :].
- globular-toast 2y agoWhy is 8080 more likely to be available than 8000?
- rad_gruchalski 2y agoDon’t worry, it’s a misunderstanding.
- disambiguation 2y agodocker pull nginx
- enriquto 2y agomini_httpd -p 8080 # and no need to install a whole python interpreter
- em-bee 2y agomost people will have python installed already, but not mini_httpd.
- smusamashah 2y agoI use voidtools Everything on windows for instant file lookup. It has an Http server built in. Whenever browser complains about a feature only available via webserver url, not local file, it comes handy. Open everything webserver, enter name of the file and click.
- starik36 2y agoI've been using Everything forever and never knew about this feature. Thanks!
- nasso_dev 2y agoFor those who have Rust, I like miniserve[1]: cargo install --locked miniserve miniserve path/to/directory [1]: https://github.com/svenstaro/miniserve https://github.com/svenstaro/miniserve
- Svenstaro 2y agoThanks for posting miniserve <3
- elcritch 2y agoCool project! Setting up a quick local HTML server can be annoying. Alas it looks like it's web/electron based. :/ Downloading it and yep, 443.8 MB on MacOS. The Linux one is a bit better at 183.3 MB. Electron really should get a kickback from disk manufacturers! ;) Shameless plug, I've been working on a HTML inspired lightweight UI toolkit because I'm convinced we can make these sort of apps and they should only be ~10-20 MB [1] with nice syntax, animation, theming, etc. I'm finally making a suite of widgets. Maybe I can make a basic clone of this! Bet I could get in < 10MB. :) 1: https://github.com/elcritch/figuro https://github.com/elcritch/figuro
- tredre3 2y agoFiguro is like Sciter but for Nim?
- elcritch 2y agoSorta! It didn’t start out that way but I’ve been building more from HTML overtime but keeping it fast and lightweight. I’ve cherry picked a subset of HTML like CSS grids which add a lot of layout power without tons of normal HTML hacks. I want to try adding a JavaScript runtime with simple DOM built on Figuro nodes instead. But there’s some issues with Nim’s memory management and QuickJs.
- cosmotic 2y agoFunny the bulk of the server is vestigial client code.
- elcritch 2y agoFigures, though I suspect that code only makes up a fraction of the binary size. Assuming it’s electron most of that bulk is chromium bits.
- tyzoid 2y agoMy usual go-to for a quick static server is: python -m http.server But variations exist for a lot of languages. Php has one built-in too
- Hyperlisk 2y agoThis looks nice with a friendly UI. I've been very happy with Caddy[1], but this seems like something I might recommend to someone that is new to the web environment. [1] https://caddyserver.com/docs/quick-starts/static-files https://caddyserver.com/docs/quick-starts/static-files
- Ingon 2y agoFor a second there, I read it as static web server [1], which is actually pretty cool itself 1: https://static-web-server.net/ https://static-web-server.net/
- efilife 2y agoYou get a whole copy of chromium doing something a simple python -m http.server would do without the 200MB overhead
- hedora 2y agoA default python install is > 200MB thoguh.
- nipperkinfeet 2y agoElectron? It's unfortunate how bad programming has become. Over 100MB for a program that could be written with native code under 1MB.
- 0x073 2y agoFunny to ship a web browser for a webserver.
- nottorp 2y agoI suppose that's why people run multi socket machines for "home labs".
- 8-prime 2y agoI think the popularity of Electron is merely a testament to the fact that native UI libraries need to step up their game in terms of approachability.
- LeonM 2y ago> native UI libraries need to step up their game in terms of approachability. Gnome does this, you can develop apps in Typescript. But, they started to migrate some of their own apps to Typescript and immediately received backlash from the community [0]. Although granted, the Phoronix forums can be quite toxic. My observation is that there is just a big disconnect between younger devs who just want to get the job done, and the more old-school community that care about resource efficients. Both are good intentions that I can understand, but they clash badly. This unfortunately hinders progress on this point. [0] https://www.phoronix.com/forums/forum/phoronix/latest-phoronix-articles/1540059-gnome-now-has-a-second-core-app-written-in-typescript https://www.phoronix.com/forums/forum/phoronix/latest-phoron...
- 8-prime 2y agoCool, I didn't know that. I agree that this is, at least often, a case of where your roots lie. Whats most shocking to me is that the likes of Apple and Mircosoft don't seem to be interested in/capable of building an actually good framework. I feel like Microsoft tried with .NET Maui, but that really isn't a viable choice if you go by developer sentiment.
- perilunar 2y agoNot sure why i need this on Mac. Apache is already installed — just drop your files in ~/Sites/ or /Library/WebServer/Documents/ .
- danpalmer 2y agoTailscale does this, you can serve a port on your Tailnet, or you can serve a directory of files, or you can expose it to the internet. Comes with HTTPS. It's pretty neat. https://tailscale.com/kb/1312/serve https://tailscale.com/kb/1312/serve
- la_fayette 2y agoI often have the requirement, during development cycles, to bring up a static Webserver. After trying several options I always happily come back to the PHP built-in Webserver: php -S localhost:8080 Many helpful options are available, just check the docs...
- 7bit 2y ago240 MB for a simple web server? You're doing something wrong. And by something, I mean everything.
- Defletter 2y agoSeems like most of the people in these comments have missed the point, as while I also lament the use of Electron, pasting one-liner scripts does not obviate the usefulness of this project. Clearly the point of this project is not just about setting up a simple webserver, but to provide a quick and easy gui to configure that webserver, and there's a fair amount that it allows you to configure. Your one-liner that does nothing but pipe static files as a response is not that. If that's all you need, great, then this project is not for you and that's okay.
- pjmlp 2y agoMissed opportunity to actually server the UI via the webserver in first place, as we used to do 25 years ago like with IIS Web management UI in my default browser.
- em-bee 2y agofor a webserver with an awesome GUI served through the web i recommend roxen. it is not a webframework requiring you to write code to serve content, but it serves static files out of the box and let's you add dynamic content on top of that. and it can outperform apache and other webservers depending on your workload.
- pjmlp 2y agoWritten in Pike, interesting.
- em-bee 2y agoto anyone concerned about needing to learn a new language, unless you want to build very custom dynamic sites you don't. to conveniently serve static files you won't ever have to touch the code. just like you wouldn't do that with apache or nginx. and even if you do want something dynamic, a lot of dynamic features can be had by embedding custom tags in html. still no code required. if you have concerns about pike as a language for the server implementation itself, pike is a very performant language with a long history being used in high profile sites and services. both pike and roxen go back to the early 90s. and if you do want to create custom features and need help you can hire me. i am looking for work (pike,js,ts,python,php,ruby,go,... ;-)
- astrod 2y agoBun does this with; bun index.html https://x.com/jarredsumner/status/1886073859138580506 https://x.com/jarredsumner/status/1886073859138580506
- vince14 2y agoBecause projects like these were missing back then, I got creative with nginx and do not need any config changes to serve new projects: server { listen 80; server_name ~^(?<sub>\w+)(\.|-)(?<port>\d+).*; # projectx-20201-127-0-0-1.nip.io root sites/$sub/public_html; try_files $uri @backend; location @backend { proxy_pass http://127.0.0.1:$port; access_log logs/$sub.access; } } Configuration is done via the domain name like projectx-20205-127-0-0-1.nip.io which specifies the directory and port. All you need to do is create a junction (mklink /J domain folder_path). This maps the domain to a folder.
- gizmo 2y agoAm I reading this wrong or does this almost open up any server bound to localhost to the outside? I think proxy_pass will forward traffic even when the root and try_files directives fail because the junction/symlink don't exist? And "listen 80" binds on all interfaces doesn't it, not just on localhost? Is this clever? Sure. But this is also the thing you forget about in 6 months and then when you install any app that has a localhost web management interface (like syncthing) you've accidentally exposed your entire computer including your ssh keys to the internet.
- miroljub 2y agoThat's why I switched to Caddy for most of my needs. I create one Caddy server template, and then instantiate it as a new host with one line per server.
- merpkz 2y ago
- bayindirh 2y agoLooks cool! If anyone wants a similar thing without a UI, there's a also webfsd [0]. It's mature, feature packed and fast. [0]: https://github.com/ourway/webfsd https://github.com/ourway/webfsd
- globular-toast 2y agoWow, this is a "full circle" moment. I can distinctly remember installing my first WAMP (Windows, Apache, MySQL, PHP) stack back in ~03 when I was learning to program. It was all easy point-and-click installers. I think I may have had to edit a config file to enable PHP, but that was it.
- pjmlp 2y agoI basically do jwebserver.exe, done.
- flessner 2y agoIt looks nice and friendly, but for developers I can recommend exploring caddy[1] or nginx[2]. It's a useful technology to have worked with, even if they're ultimately only used for proxying analytics. [1] https://caddyserver.com/ https://caddyserver.com/ [2] https://nginx.org/ https://nginx.org/
- ozim 2y agoSecond that, I don't really see reason not to run proper web server actually especially if one does web development and would use it for multiple projects anyway.
- I_complete_me 2y agoMy goto is https://libraries.io/pypi/beautify-http-server https://libraries.io/pypi/beautify-http-server; upload files and everything. I have it running on my Raspberry Pi.
- TotallyRealDev 2y agoYou might want to remove the semi-colon
- I_complete_me 2y agoToo late to edit. Here's a better clickable: https://pypi.org/project/beautify-http-server/ https://pypi.org/project/beautify-http-server/
- meonkeys 2y agoWhat is libraries.io? Why not link to the official pypi page? https://pypi.org/project/beautify-http-server/ https://pypi.org/project/beautify-http-server/
- I_complete_me 2y agoSorry I rushed the URL. I was focused on presenting the name of the package. I have no idea what libraries.io is.
- theonething 2y agopython3 -m http.server 8000
- kakuri 2y agonpx http-server (keep the "r" at the end, it's more up-to-date than the http-serve package) https://github.com/http-party/http-server https://github.com/http-party/http-server
- deleted 2y ago[deleted]
- sltr 2y agodocker run --rm -p 8080:80 -v "$(pwd):/usr/share/nginx/html:ro" nginx:alpine will host the current directory on 8080
- fulafel 2y ago... open to the internet, adding an allow rule to the host firewall (at least on linux)