jaschaephraim/lrserver

Middleware support?

matthewmueller opened this issue · 6 comments

Hey thanks for creating this :-)

I was wondering if it makes sense in the scope of this project for the livereload server to implement an http.Handler interface?

It would allow less port binding and would be a bit easier to integrate into existing dev servers.

@matthewmueller Great idea. I'll update in the next week or so.

Well I'm only a year late, but I had a chance to take another look at this and decided this feature would be beyond the scope of the project. I'll maintain this repo as a simple, solid, standalone server, but probably won't be adding any features in the future.

Haha fair enough! Funnily enough, I looked at this again last week and created a version that does implement it as middleware. It's heavily influenced by your work, so thanks for that!

I need to clean it up, but I'll post a link here once it's public to let others choose what works best for them.

Awesome! Yes please keep me posted, I'll be sure to link to your project in the readme.

@matthewmueller would be awesome if you've got a live reload implementation that you are ready to post long with the lrserver one!

Haha, the thread that keeps getting forgotten and revived 😁

Here's the code: go-livereload-master.zip

It is working. It's just untested and undocumented. Example usage:

middleware := livereload.Watch("*.js")
router := some.Router()
handler := middleware(router)
http.ListenAndServe(":9000", handler)

Sorry for the bare minimum of effort. I didn't make progress since the last message and I probably won't for the foreseeable future. Maybe this is better than nothing? 🤷‍♂️

If anyone has the urge, I'd love for someone to clean it up and open source it. The license is MIT. Feel free to make it your own.