
Knod – A Tiny HTTP server for your current directory with writes - TinyBig
https://github.com/moserrya/knod
======
hopeless
Yes, yes, all these one-liner http server are great… but you're missing the
point

Knod allows you to POST JSON data to a URL which it stores in a file so you
can GET the same data back. If you're prototyping a one page JS app in, say,
Ember this means that you don't need work on the backed logic, server or
database. It's a pretty smart idea!

I wonder what it does on GET /items though? Hopefully it concatenates all file
contents into a JSON array

~~~
ImJasonH
Yeah, a fake "sticky" backend can be really useful in prototyping a frontend.

I built a similar thing to help with that, built on App Engine (which I
usually just run locally): [https://github.com/ImJasonH/simply-
put](https://github.com/ImJasonH/simply-put)

It supports GET/POST/DELETE and simple queries.

I ended up having more fun writing the devel backend than whatever it was I
was writing :)

------
jamescun
While it doesn't support writing (POST/PUT etc), for serving files over HTTP
from the current directory, Python's built in HTTP server is perfectly fine.
It comes with Python 2.4+ as standard.

    
    
        python -m SimpleHTTPServer

~~~
pekk
I wish this weren't true, but it's a terrible server - all but unusable. Just
try to serve requests to several hosts within the same few seconds.

~~~
tdicola
I don't think it was ever meant to be a server beyond a single user on a
single machine. It's great for spinning up a server to start prototyping some
web pages, etc. locally. Trying to serve content to multiple users (especially
at the same time) is asking for trouble.

------
TinyBig
It's an HTTP server that allows reading and writing, hence it is different
than the static file servers built into many languages.

------
avidal
So, you can only bind to '0.0.0.0'? Which means, by default, you're opening up
read/write to the specified directory without permissions, to the entire
world?

Maybe the default should be 127.0.0.1; and if the user specifies 0.0.0.0 then
it comes with a big fat warning?

------
FrozenCow
I have worked on a similar server off and on, but it was mostly for GET/PUT-
ing HTML files (and not JSON data). That way you could put the contents of
`document.documentElement.outerHTML` right back to where the page was
retrieved from. The developer tools of the browser, as well as
`contenteditable` can be used to create a relatively convenient HTML/content
editor.

Additionally the pages were retrieved/saved from a local bare git repository
and when some file was PUT it would be saved in a new commit and the branch
would be updated. It allowed more collaboration, since multiple people could
work on the same page without overwriting each others work.

Anonymous editing isn't yet implemented, but the idea is to have anyone being
able to make changes (with some restrictions) and offer it to the site's owner
(kind of like a pull request). It would allow wiki-like functionality for
websites in general.

Javascript was used for more specialized editing tools, like adding rows to
certain tables and calculating totals (for example for [HTML5
invoices]([http://www.jonathantneal.com/blog/the-
html5-invoice/)](http://www.jonathantneal.com/blog/the-html5-invoice/\))).
Remove DOM elements when you're done editing and PUT the page back.

Recently I felt a bit constricted with this model, since some parts of the
pages needed to be reused across multiple pages (like 'master pages' or
blogpost entries). I've implemented a simple 2-way templating engine. Static
pages can be built from the templates and from the page you could extract the
templates, without losing data. That way you could edit the page as-is, but
the parts that are templated are saved in the template (and reused in other
pages). It did make the server more complex than a simple GET/PUT server, but
the GET/PUT functionality was still preserved.

I see a lot of potential in such a GET/PUT server. With the right permissions
for PUT operations, this can also be quite a decent 'CMS'-like server.

------
jtdowney
Ruby already has the ability to spin up a quick webserver for the current
directory. This is supported through the un file in Ruby's stdlib:
[http://ruby-doc.org/stdlib-2.0.0/libdoc/un/rdoc/Object.html](http://ruby-
doc.org/stdlib-2.0.0/libdoc/un/rdoc/Object.html).

    
    
        ruby -run -e httpd -- --port=8080 .

~~~
marcosnils
Say no more!.

------
___rob_m
Looks good. I wrote something similar, a small gem called Ferver, no writes
but you can point it to any directory then list or download files. Built on
top of Sinatra.

[https://github.com/rob-murray/ferver](https://github.com/rob-murray/ferver)

------
drhayes9
Just chiming in with Node's http-server: [https://www.npmjs.org/package/http-
server](https://www.npmjs.org/package/http-server)

~~~
dkordik
This has noticeably better performance than the python built-in http server in
my experience.

~~~
drhayes9
That's why I prefer it. A dev site with a bunch of resources could wedge the
SimpleHTTPServer every couple of page loads. Still haven't overwhelmed http-
server.

------
davidbanham
Why not use couchDB? It's marginally more work to deal with the _rev when
updating a document, but you've then got a much more useful prototype.

~~~
nl
Because then you need another webserver for the static files.

------
rbosinger
I get this:

`<class:Server>': undefined method `using' for Knod::Server:Class
(NoMethodError)

Am I a loser?

~~~
TinyBig
It requires Ruby 2.1

------
semiquaver
You can do this in ruby using:

    
    
        ruby -run -e httpd . -p 5000

