TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Knod – A Tiny HTTP server for your current directory with writes

76 pointsby TinyBigalmost 11 years ago

11 comments

hopelessalmost 11 years ago
Yes, yes, all these one-liner http server are great… but you&#x27;re missing the point<p>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&#x27;re prototyping a one page JS app in, say, Ember this means that you don&#x27;t need work on the backed logic, server or database. It&#x27;s a pretty smart idea!<p>I wonder what it does on GET &#x2F;items though? Hopefully it concatenates all file contents into a JSON array
评论 #7807354 未加载
评论 #7807667 未加载
评论 #7808674 未加载
jamescunalmost 11 years ago
While it doesn&#x27;t support writing (POST&#x2F;PUT etc), for serving files over HTTP from the current directory, Python&#x27;s built in HTTP server is perfectly fine. It comes with Python 2.4+ as standard.<p><pre><code> python -m SimpleHTTPServer</code></pre>
评论 #7806462 未加载
评论 #7807082 未加载
评论 #7806843 未加载
评论 #7806485 未加载
评论 #7807042 未加载
评论 #7807374 未加载
评论 #7806757 未加载
TinyBigalmost 11 years ago
It&#x27;s an HTTP server that allows reading and writing, hence it is different than the static file servers built into many languages.
avidalalmost 11 years ago
So, you can only bind to &#x27;0.0.0.0&#x27;? Which means, by default, you&#x27;re opening up read&#x2F;write to the specified directory without permissions, to the entire world?<p>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?
FrozenCowalmost 11 years ago
I have worked on a similar server off and on, but it was mostly for GET&#x2F;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&#x2F;content editor.<p>Additionally the pages were retrieved&#x2F;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.<p>Anonymous editing isn&#x27;t yet implemented, but the idea is to have anyone being able to make changes (with some restrictions) and offer it to the site&#x27;s owner (kind of like a pull request). It would allow wiki-like functionality for websites in general.<p>Javascript was used for more specialized editing tools, like adding rows to certain tables and calculating totals (for example for [HTML5 invoices](<a href="http://www.jonathantneal.com/blog/the-html5-invoice/)" rel="nofollow">http:&#x2F;&#x2F;www.jonathantneal.com&#x2F;blog&#x2F;the-html5-invoice&#x2F;)</a>). Remove DOM elements when you&#x27;re done editing and PUT the page back.<p>Recently I felt a bit constricted with this model, since some parts of the pages needed to be reused across multiple pages (like &#x27;master pages&#x27; or blogpost entries). I&#x27;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&#x2F;PUT server, but the GET&#x2F;PUT functionality was still preserved.<p>I see a lot of potential in such a GET&#x2F;PUT server. With the right permissions for PUT operations, this can also be quite a decent &#x27;CMS&#x27;-like server.
jtdowneyalmost 11 years ago
Ruby already has the ability to spin up a quick webserver for the current directory. This is supported through the un file in Ruby&#x27;s stdlib: <a href="http://ruby-doc.org/stdlib-2.0.0/libdoc/un/rdoc/Object.html" rel="nofollow">http:&#x2F;&#x2F;ruby-doc.org&#x2F;stdlib-2.0.0&#x2F;libdoc&#x2F;un&#x2F;rdoc&#x2F;Object.html</a>.<p><pre><code> ruby -run -e httpd -- --port=8080 .</code></pre>
评论 #7806956 未加载
___rob_malmost 11 years ago
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.<p><a href="https://github.com/rob-murray/ferver" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rob-murray&#x2F;ferver</a>
drhayes9almost 11 years ago
Just chiming in with Node&#x27;s http-server: <a href="https://www.npmjs.org/package/http-server" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.org&#x2F;package&#x2F;http-server</a>
评论 #7806728 未加载
davidbanhamalmost 11 years ago
Why not use couchDB? It&#x27;s marginally more work to deal with the _rev when updating a document, but you&#x27;ve then got a much more useful prototype.
评论 #7808486 未加载
rbosingeralmost 11 years ago
I get this:<p>`&lt;class:Server&gt;&#x27;: undefined method `using&#x27; for Knod::Server:Class (NoMethodError)<p>Am I a loser?
评论 #7807403 未加载
semiquaveralmost 11 years ago
You can do this in ruby using:<p><pre><code> ruby -run -e httpd . -p 5000</code></pre>