7 ms·
Show HN: Wd-40, a static webserver with automatic hot-reloads
It works by injecting a websocket script which listens for file changes. The filechanges are detected using the go fsnotify package, which in turn uses the different OS's equivalent to inotify.
I basically got bored with alt-tabbing and refresing when developing 'vanilla-js'. The hot-reload in the modern frameworks are very nice, so figured I'd recreate it.
- pwg 2y agoMy only comment is: "be prepared for a cease and desist from the lawyer's for the real WD-40 company" over the name choice. The fact that they make spray lubricants and you have a website re-loader will likely not make any difference to them.
- baalimago 2y agoHmm.. That's a good point, thank you. I'll change the name
- SvenL 2y agoGood job with the renaming - WD-42 could have been also a good choice.
- bankcust08385 2y agoI also hate WD-40 as a product because it's marginally useless as a lubricant or as a penetrating oil when there are far better products for each use.
- written-beyond 2y agoI sprayed it near my squeaky bike brake hinge thinking it would remove the squeak. I now know I was an idiot and completely ruined the bike's brakes.
- TomK32 2y agoBrake cleaner for diskbrakes unless it's a sound of metal on metal and you have to replace the brake pads. And for rim brakes if there's a metal sound a stone is stuck in the rubber part of the brakes, either get it out or replace as well if it's already worn down a fair bit.
- Lionga 2y agoJust be happy you learned that lesson on a bike and not on a car
- fnord77 2y agoIt's excellent for Water Displacement, which is what its purpose actually is. Such as if you have ignition wires soaked with water and shorted, it will get you going again.
- rzzzt 2y agoIt's a brand name now, they also sell grease.
- Bluestein 2y agoMe wonders - remembering the recent here post about the flooded underground silo with electronics - could it be flooded with WD-40 instead of water?
- adrianN 2y agoThe common recommendation is to flood wet electronics first with distilled water and then with isopropyl alcohol
- DiggyJohnson 2y agoThat comment has been living in my head rent free all week. The author of that post was good with imagery.
- dghughes 2y agoI'd say because it's not a lubricant it's penetrating oil, anti rust, anti moisture (its original purpose). And even when used as that most people I'd guess don't shake the can, a long shake, as required.
- _heimdall 2y agoI have much better luck with PB Blaster. I can't count how many rusty old nuts and bolts I sprayed with WD-40 only to have to follow it up with PB Blaster to get the job done.
- api_or_ipa 2y agoPB Blaster is the product everyone thinks WD-40 is. Even still, I wouldn’t use it in the place of real oil/grease/lubricant but in a pinch it’s far better than WD-40 for those odd chores.
- _heimdall 2y agoFor sure. PB Blaster is my go-to when I find a bolt on my truck that hasn't been touched since it left the factory in '88. Its a quick fix for a stuck bolt, but still not a great solution for a squeaky door hinge.
- fullstop 2y agoThey (WD-40 brand) do sell a penetrating oil: https://www.wd40.com/products/penetrating-oil/ https://www.wd40.com/products/penetrating-oil/
- mikkom 2y agoUsing the same name also will make searching anything related to this much more difficult (as will using 2 letter 2 number name)
- alpb 2y agoIt’s wd-41 now lol
- lenerdenator 2y agoReally should rename it tap-and-die.
- ranger_danger 2y agodo you know what a hammer is? I tell you hwat
- ranger_danger 2y ago> not make any difference to them. It does to the US government... trademarks are industry-specific. It is absolutely legal for people to use the exact same trademark for different classes of business. Of course they could still probably sue you into oblivion anyways, even if they're wrong.
- anticensor 2y agoTrademarks have scopes.
- dufzh 2y agoSounds similar to the 'live server' plugin in vscode
- Alifatisk 2y agoDoes it support SSI?
- Brajeshwar 2y agoI thought the name was inspired by a cheap, easily available lubricant that comes in handy for every home. I've tried many simple servers for experimenting with simple static websites (HTML, CSS, JS). I'm currently settled on LiveReload[1] and BrowserSync[2]. LiveReload attaches to other tooling and is more straightforward, while Brower-Sync when looking across a few multiple browsers (out of habit). I'm not particularly fond of tooling that attaches to an IDE, but I like more of the ones that I can pipe with arguments. But then again, I do straightforward stuff these days. LiveReload should also be easily attachable to a simple `python -m SimpleHTTPServer 8000`. 1. https://github.com/livereload https://github.com/livereload 2. https://browsersync.io https://browsersync.io
- baalimago 2y ago>I thought the name was inspired by a cheap, easily available lubricant that comes in handy for every home. It is, especially it's rust-repellent properties. The only 'plug-and-play' static webserver I found was, well... https://github.com/static-web-server/static-web-server/ https://github.com/static-web-server/static-web-server/ which is written in Rust (I didn't look around super hard). But, being a gopher, and since it lacked live reload, I wrote my own.
- antman 2y agoIt would be self defeating if written in Rust
- seanthemon 2y agoExcept "rust" in rust isn't about iron oxidation, but rather a fungi [0] [0] https://www.reddit.com/r/rust/comments/27jvdt/internet_archaeology_the_definitive_endall_source/ https://www.reddit.com/r/rust/comments/27jvdt/internet_archa...
- sgu999 2y agoDoesn't seem that final in that extract. > <graydon> > A little. Also big metallic things. And rusts and smuts, fungi. And it's a > <graydon> > nice substring of "robust". > <graydon> IOW I don't have a really good explanation. it seemed like a good name. (also a substring of "trust", "frustrating", "rustic" and ... "thrust"?) > <graydon> but then everyone thinks it's a pun on "chrome" so maybe we should stick with that And given that now all the lore around it is about oxidation, I guess that's what stuck? These old IRC dumps make me nostalgic instantaneously. There was a time not that long ago when we were still mostly fine with plain text for complex communications.
- AbraKdabra 2y agoI really don't know how you didn't think of the "dodging potential lawsuit" before posting it here, I mean, you didn't know that using actual product names is wrong? It's a shame though, I liked the word play.
- lukan 2y agoNot a lawyer, but I think it might be ok, if the products are totally unrelated, which they are. I doubt anyone at the management of the company behind WD-40 would even know what a http server is, or could name one. Also, it is written Wd-40 not WD-40.. As long as it stays a dev http server, it should be fine.
- winter_blue 2y agoThis is pretty cool. I have two questions, regarding the mirroring: 1. For the mirroring, are you using something like rsync (with modifications for the web socket script injection) underneath? Also, will the mirroring reflect destructive changes (like rsync's --delete flag), like if a directory or file is deleted in the original content directory? 2. Could you avoid mirroring the content directory, and just directly serve the original content directory, by just simply on-the-fly injecting the relevant script tag in text/html files? (Or, only mirroring those text/html files, and serving the remaining files from the original content directory.)
- baalimago 2y ago1. No, it doesn't react to file additions/deletions at the moment, but as there's support for this in fnotify which is handling file change notifications [1] I'll add this shortly. wd-41 is still quite early in development. 2. This was my initial idea as well: to simply inject the ws-load script tag on the fly. But it would require basically writing a static file server from scratch, which I didn't feel like doing (I have a blog to write, not static file servers!). Currently the solution is based on the go standard library fileserver handler [2] which makes the solution simple and effective. So i decided on the mirrored approach with the idea that the result for the end user should be the same, apart for the temporary directory where the mirrored files lives. I haven't yet detected any speed-issues in the mirroring process or the file-watch process, which I think is the only downside (please correct me if I'm wrong). [1]: https://pkg.go.dev/github.com/fsnotify/fsnotify#hdr-Watching_directories https://pkg.go.dev/github.com/fsnotify/fsnotify#hdr-Watching... [2]: https://github.com/baalimago/wd-41/blob/main/cmd/serve/serve.go#L68 https://github.com/baalimago/wd-41/blob/main/cmd/serve/serve...
- wannacboatmovie 2y agoStatic web servers have been a solved technical problem for going on 25 years.
- whiterknight 2y agoIs there a small and portable one you recommend?
- hawski 2y agoI personally like busybox httpd, because sometimes it already is there.
- wannacboatmovie 2y agomini_httpd, merecat, [a-z]httpd (choose one), OpenBSD httpd is nice but not portable. Your OS likely has a a built-in web server. Hell, Microsoft shipped something called Personal Web Server with Windows 95/98 nearly 30 years ago. Stop inventing new static web servers. Contribute patches to an existing project if you feel so inclined but this has been a solved problem for decades by very intelligent people who understand how the Internet works. We've gone full circle from bloated behemoths like Netscape, to serving from kernel mode (http.sys, Tux Web Server, etc.) and back again.
- whiterknight 2y agoThese responses are telling me there is in fact room in the market. Take pdf viewers for example. I hated all of them until I found Zarthura. I’m glad someone took the time to make that.
- dhc02 2y agoSomeone above recommended devd, and it looks pretty nice. https://github.com/cortesi/devd https://github.com/cortesi/devd
- mrweasel 2y agoYeah, but this one actually refreshes the browser when a file is modified on disk (of the server). I don't recall seeing that in any other webserver, at least not out of the box. It is pretty clever, not sure how much need I have for it, but it's an interesting idea.
- onetom 2y agoI've settled on devd (modd) for the past few years. https://github.com/cortesi/devd https://github.com/cortesi/devd It's a single file go executable. Supports CORS too. I use it via direnv & nix-shell.
- password4321 2y agoI am the self-appointed HN sales pitch for https://github.com/sigoden/dufs https://github.com/sigoden/dufs, a fileserver including webdav.
- leejoramo 2y agoDoes dufs have the auto reload feature of this project?
- password4321 2y agoNo auto/live/hot reload, just a well-maintained single (rust) binary static fileserver with .zip, upload, auth, & webdav.
- leejoramo 2y agoI am a big fan of WebDAV. DUFS is new to me, I will check it out.
- mixmastamyk 2y agoYou can do this with inotify-tools and a wrapper script. Needs a little something on the browser side to make it seamless however.
- est 2y agoI am glad such tool exists, but PHP was "hot-reloading" like what, 20 years ago?
- nashashmi 2y agoShould W3C work on a way to do socket connections without JS? It is not high on the list but is popular enough. Things that are more important to be done without JS are horizontal scrolling of items (marquee on steroids?) and slideshows,
- 1oooqooq 2y agobetween this and liveview... and the infinity websites doing timed or pull-check reloads... is this the best the web have to offer in terms of standards to keep one tab with fresh content? i recall some push standard discussions
- giancarlostoro 2y agoI assume WebSockets is probably the preferred way so all the other proposals fell on their face. This one seems to be using WS as well.
- wolfgang42 2y agoThere’s also Content-type: multipart/x-mixed-replace, though last I checked it had the downsides of (a) only working in Firefox and (b) causing the loading spinner to run forever.
- pierrec 2y agoNice, I've used an editor plugin for this before, but I like that this isn't tied to any specific editor. Actually Hugo also does this, though again that's tied to a framework: https://gohugo.io/getting-started/usage/#livereload https://gohugo.io/getting-started/usage/#livereload Also curious about this: "The delta-streamer.js script then checks if the current window origin is the updated file. If so, it reloads the page." Does that mean it doesn't auto-refresh if dependencies (scripts, stylesheets, etc) are updated? Maybe there's room for improvement here though I'm not sure how I would approach it. Maybe just an option to skip the check would do the job.
- baalimago 2y ago>Does that mean it doesn't auto-refresh if dependencies It does refresh on all other file changes. I first thought about trying to figure out what js/css was used on which page but that turned too complicated. So now it refreshes on all js/css files [1]. [1]: https://github.com/baalimago/wd-41/blob/main/internal/wsinject/delta_streamer.ws.go#L34 https://github.com/baalimago/wd-41/blob/main/internal/wsinje...
- drpossum 2y agoHere's literally the same link to a repo from the author from two days ago https://news.ycombinator.com/item?id=41284189 https://news.ycombinator.com/item?id=41284189 How many times do you feel the need to repeatedly hype this?
- lukan 2y agoYour link, links to this thread ..
- bufferoverflow 2y agoSo what happens when you have more than 64K simultaneous viewers?
- meblum 2y agoHere’s my hot-reload tool https://github.com/meblum/serv https://github.com/meblum/serv it reloads html files when any of its dependencies have changed. Written in Go with zero dependencies and requires no config. Uses server-sent-events to notify webpage of updates. Feedback appreciated.