Hacker News new | past | comments | ask | show | jobs | submit login
Spark web server (github.com/rif)
54 points by rif on Feb 12, 2014 | hide | past | favorite | 49 comments



As opposed to Spark, the microcontroller platform. As opposed to Spark, the resilient distributed data system. As opposed to Spark, the open source IM client.


... as opposed to Spark (http://www.sparkjava.com/), the Java web server.


...as opposed to Spark[1], the tool by @holman.

[1]http://zachholman.com/spark/


Yep, should've gone with Zitser or Poppler.


You were probably being facetious, but Poppler is already used too (PDF rendering library).


Would've made more sense for a POP email library.


Is 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.


I'm so sick of seeing this pattern of 1) person makes tool they find useful, 2) person releases tool publicly for free, 3) other person comes across tool but doesn't find it useful, 4) other person publicly denigrates tool as being universally not-useful.

I just don't get it.


@dangerlibrary simply says: Do not re-invent the wheel. I cannot see any real-world production environment where this new server is better approach then activating a tiny config file. Thus, it is a very good lesson to the author: Use what is out there and build what is missing.


I very rarely see a "hey I made this!" post here that doesn't include one or more comments along the lines of "this already exists!". I don't mind these sorts of comments when they tell me something I didn't know - "you can achieve something similar by doing coodle with well-known tool doodle!", "there is somewhat-obscure tool foodle that does exactly this!" - there are some comments like that in this thread. What I dislike is when these sorts of comments are along the lines of, "you should have just done the thing that you made the tool to avoid having to do!". It is just dismissal and leaves nobody the wiser.

It seems delusional to think that this sort of comment is somehow a good learning experience for a library author. Everyone knows that you shouldn't reinvent the wheel, but there are reasonable disagreements on what exactly that means.


I don't think I said anything negative about the tool itself, or about the author of the tool, who seems perfectly happy with it.

You're right that I don't think it's useful to have a proliferation of tools that do one thing worse than a general-purpose tool.

I don't want an avocado peeler - I'll use a knife and I'll recommend using a knife to others.


It's your tone more than anything. I read some of your previous posts to see if you were a d-bag and I came to the conclusion that you're not[1]. This reads more like the post was a button-pusher for you. I can relate. :)

Unfortunately, even with the tone removed, the comment hits that "top-voted middlebrow" button for many of the other people on the site. I would however say that for TFA itself as well.

[1] the opinion of some random interdweeb carries a lot of weight, I know. :)


Great. Good for you.

Your initial comment, however, is filled with a denigrating tone. It is that tone your parent is addressing. Not so much the content. The tone. It is unkind.


Does 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.


You 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"


You 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 :)


The way I'd do this is have front-end load balancers just re-direct to a nginx configured just for this purpose.


Yes it does, although not out of the box:

http://wiki.nginx.org/HttpEchoModule


You don't actually need echo, you can use return from the rewrite module (which is compiled in by default).

    return 503 "<h1>Maintenance</h1><p>will be back soon!</p>";


lol, I love hackers :)


Oh yeah. That's rad.


:)


    # pgrep nginx
    #


You could achieve something similar using the simple HTTP server shipped with python: python -m SimpleHTTPServer


Which will melt with any sort of sustained traffic.


Except, 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 :)


Yes 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?


If you just want a small httpd there's also gatling and fnord.

[0] http://www.fefe.de/gatling/ [1] http://www.fefe.de/fnord/


Or webfsd. or bozohttpd or...


this one has 45 lines of code :)


Well, the binary contains a lot of go.


That's true of anything written in Go.


Yes, 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.


The go team is aware of this and I think it will improve soon: http://talks.golang.org/2014/go1.3.slide#1


Which is what I was getting at...


What I meant was that almost all the HTTP stuff is in "net/http".


I was wondering why I would want this, but being able to pass some HTML on the command line is pretty cool.


[deleted]


You can give it a string or a single file, not only a dir.


I 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.


Added a parameter to stet the desired status


Good point!


python -m SimpleHTTPServer 8080

Above will serve whatever files you have in $PWD


And be _insanely_ slow (not just the normal, python is slow comment - there are fast web servers in python; SimpleHTTPServer is not).


Thanks! 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.


Can someone explain this function signature? I can't grep it.

func (h bytesHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)


The 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.


you 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.


byteHandler 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.


I'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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: