TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

76 点作者 TinyBig将近 11 年前

11 条评论

hopeless将近 11 年前
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 未加载
jamescun将近 11 年前
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 未加载
TinyBig将近 11 年前
It&#x27;s an HTTP server that allows reading and writing, hence it is different than the static file servers built into many languages.
avidal将近 11 年前
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?
FrozenCow将近 11 年前
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.
jtdowney将近 11 年前
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_m将近 11 年前
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>
drhayes9将近 11 年前
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 未加载
davidbanham将近 11 年前
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 未加载
rbosinger将近 11 年前
I get this:<p>`&lt;class:Server&gt;&#x27;: undefined method `using&#x27; for Knod::Server:Class (NoMethodError)<p>Am I a loser?
评论 #7807403 未加载
semiquaver将近 11 年前
You can do this in ruby using:<p><pre><code> ruby -run -e httpd . -p 5000</code></pre>