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.

Shinatra – A simple bash web server

42 pointsby Bokaghaover 8 years ago

16 comments

minhajuddinover 8 years ago
Many people here fail to realize, this is an <i>excellent</i> debugging server. I used to have a server to print out the body and headers of requests when building an api to make sure things were going (the right headers and request body) out as expected <a href="https:&#x2F;&#x2F;github.com&#x2F;minhajuddin&#x2F;httpdebug&#x2F;blob&#x2F;master&#x2F;app.go" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;minhajuddin&#x2F;httpdebug&#x2F;blob&#x2F;master&#x2F;app.go</a>.<p>This is a much lighter and nicer version. This is going into my ~&#x2F;bin&#x2F;httpdebug :)<p>You can try sending a few curl requests to see that this really prints the headers and body.<p><pre><code> curl -H &quot;api-key: Foo&quot; -X POST --form name=Khaja http:&#x2F;&#x2F;localhost:8080&#x2F;</code></pre>
评论 #13024908 未加载
评论 #13023560 未加载
kowdermeisterover 8 years ago
I think the point here is to demonstrate that one might think that web servers are mystical beasts (true) but after all, they &quot;just&quot; return a HTTP header and some content.
评论 #13026027 未加载
zimbatmover 8 years ago
And the HTTP client:<p><pre><code> exec 3&lt;&gt;&#x2F;dev&#x2F;tcp&#x2F;localhost&#x2F;8080 echo -e &quot;GET &#x2F; HTTP&#x2F;1.1\n\n&quot; &gt;&amp;3 cat &lt;&amp;3</code></pre>
djsumdogover 8 years ago
That was both funny and disappointing. I thought it world at least serve static files. Putting netcat in a for loop is hardly a web server in bash.
z3t4over 8 years ago
Bash (shell-script) is a very powerful language, but a bit too complicated for the non-programmer (computer hacker). Then we got Perl, but it is also a bit too complicated. Now we have JavaScript doing the same thing, but also JavaScript (ES6) is now getting more complicated. I wonder is there a rule that says a (scripting) language for non-programmers will eventually either die or end up being too complicated for non-programmers ?
评论 #13021552 未加载
评论 #13021544 未加载
satori99over 8 years ago
&gt; Does it work on Windows?<p>&gt; Of course not.<p>It works just fine on Windows 10 with WSL.
评论 #13021393 未加载
Spydar007over 8 years ago
This reminds me a lot of Certbot&#x27;s use of the Python SimpleHTTPServer:<p><pre><code> $(command -v python2 || command -v python2.7 || command -v python2.6) -c &quot;import BaseHTTPServer, SimpleHTTPServer; s = BaseHTTPServer.HTTPServer((&#x27;&#x27;, {port}), SimpleHTTPServer.SimpleHTTPRequestHandler); s.serve_forever()&quot;</code></pre>
评论 #13022497 未加载
Demcoxover 8 years ago
Five lines seems like much when you consider that one can write a concurrent (using threads) C webserver in 12...
评论 #13021274 未加载
评论 #13021420 未加载
gregn610over 8 years ago
I had to look up the colon minus syntax, here&#x27;s the answer <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;10390406&#x2F;usage-of-in-bash" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;10390406&#x2F;usage-of-in-bash</a>
andrewstuartover 8 years ago
It&#x27;s more a port responder.
ominousover 8 years ago
While googling for this, found a &quot;Big list of http static servers&quot;: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;willurd&#x2F;5720255" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;willurd&#x2F;5720255</a><p>Not that big.
Jaruzelover 8 years ago
&gt; Is this a thread based server, or does it use an event loop instead?<p>&gt; No.<p>Well, which is it ?
评论 #13021409 未加载
评论 #13021411 未加载
anc84over 8 years ago
Clickbait - A web server in one line of bash:<p><pre><code> $ nginx</code></pre>
arpaover 8 years ago
not to be that guy, but that&#x27;s<p>1. hardly a web server<p>2. hardly pure bash<p>of course writing a server of anything in pure bash is a tad bit difficult, as opposed to a client - bash can connect(), but can&#x27;t bind() &#x2F; listen() nor accept() unless, of course, you use something to expose these syscalls, but that opens a whole another can of worms...
评论 #13026921 未加载
longsleepover 8 years ago
Whats the point of this?
EJTHover 8 years ago
So this is babys first netcat server? Someone is overly proud of using a command like it was intended...