7 ms·
Spark web server
Little web server for emergencies
- michaelmior 13y agoI was wondering why I would want this, but being able to pass some HTML on the command line is pretty cool.
- Alan_ 13y agoI can't see anywhere in the code so assume this returns a 200 code for requests. If was using this to show maintenance for my website would want it to return 503.
- raimue 13y agoYou could achieve something similar using the simple HTTP server shipped with python: python -m SimpleHTTPServer
- kordless 13y agoWhich will melt with any sort of sustained traffic.
- hysan 13y agoExcept, that's not the use case for Spark so it's an apt comparison. > Emergency web server > For those occasions when your webserver is down and you want to display a quick maintainance note. Or just want to quickly demo a static site. Or whatever :)
- dkuntz2 13y agoYes it is. The use case is when your site is down and you want to tell people that. If you have even a small amount of traffic `python -m http.server` is going to die, this isn't. How is that not an apt comparison?
- deleted 13y ago[deleted]
- rif 13y agoYou can give it a string or a single file, not only a dir.
- deleted 13y ago[deleted]
- rektide 13y agoAs opposed to Spark, the microcontroller platform. As opposed to Spark, the resilient distributed data system. As opposed to Spark, the open source IM client.
- dewey 13y agoIf you just want a small httpd there's also gatling and fnord. [0] http://www.fefe.de/gatling/ http://www.fefe.de/gatling/ [1] http://www.fefe.de/fnord/ http://www.fefe.de/fnord/
- rif 13y agothis one has 45 lines of code :)
- bestham 13y agoWell, the binary contains a lot of go.
- dkuntz2 13y agoThat's true of anything written in Go.
- ploxiln 13y agoYes, but, trivial c programs statically linked with glibc can be in the ballpark of 500KiB, trivial c programs statically linked with uclibc or similar can be in the ballpark of 100KiB, and trivial go programs (always statically compiled) can be 2-5 MiB. They're huge.
- bestham 13y agoWhat I meant was that almost all the HTTP stuff is in "net/http".
- dangerlibrary 13y agoIs it really that hard to add 5 lines of boilerplate to your nginx conf? You can probably just copy-paste an existing server{} block or sites-available file and change the root directory. As a bonus, you'll learn a bit about how to configure the same tool you'll use later in production. Oh. It's written in Go. Got it.
- rif 13y agoDoes nginx have a directive for serving this text quickliy: <h1>Maintenance</h1><p>will be back soon!</p> Oh. It's written in C. Got it.
- dangerlibrary 13y agoYou still need to stop the existing web server to get spark to take over port 80, and restart it when you are done, so it's not quite that simple. Also, it's not hard to keep a maintenance conf file around, pointing to a different directory. At least, it's certainly no harder than downloading a second web server. Then it's just "sudo ln /etc/sites-available/maintenance /etc/sites-enabled/conf"
- rif 13y agoYou are so right, still I had a need for such a little tool and I don't regret any of it's 48 lines of code so far :)
- theonewolf 13y agoThe way I'd do this is have front-end load balancers just re-direct to a nginx configured just for this purpose.
- dangayle 13y agoYes it does, although not out of the box: http://wiki.nginx.org/HttpEchoModule http://wiki.nginx.org/HttpEchoModule
- 13y ago
- incidence 13y agoThanks! I have have been using "python -m SimpleHTTPServer" a lot, it is kind of a pain in the ass since it hangs sometimes in a weird way.
- swah 13y agoCan someone explain this function signature? I can't grep it. func (h bytesHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
- zek 13y agoyou have to get used to get go's backwards type declaration. This is defining a method on h which is a byteHandler struct called serve which takes a http.ResponseWriter and Request and returns nothing. This is from the http.Handler interface, so defining this method causes byteHandler to conform to the http.Handler interface.
- zaphar 13y agobyteHandler is not a struct it's a byte slice. This is actually somewhat important since it highlights a nice feature of go where you can declare methods on any baseType by aliasing them to your own type. There is no struct involved here and there doesn't need to be which is nice.
- ihsw 13y agoI've found that when discussing Go, the terms `struct` and `type` are usually used interchangeably. Yes it's factually incorrect, but the message is at least intelligible.
- BarkMore 13y agoThe type bytesHandler is a slice of bytes: type bytesHandler []byte The code func (h bytesHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { w.Write(h) } is a method declaration for the type bytesHandler. The (h bytesHandler) specifies id and type of the method receiver.
- jjoe 13y agopython -m SimpleHTTPServer 8080 Above will serve whatever files you have in $PWD
- dbpatterson 13y agoAnd be _insanely_ slow (not just the normal, python is slow comment - there are fast web servers in python; SimpleHTTPServer is not).