$ ruby -run -ehttpd . -p8000
The -r option requires un.rb[1] which is a file full of convenience functions, such as httpd in this example. Classic Ruby.Given that go has popularized long args with a single hyphen (-name etc), it is easy to mistake -run as an option by itself.
Why did they do that?
It took us 20 years to standardize on - for short and -- for long, with occasional finger rage on tar or find, and now this?
What were they thinking?
This overall attitude has led to many design decisions in Go, which define the language for better or worse. Statically-linked executables, for instance, contributed more than anything else to Go's popularity as a CLI tool language. Of course, the Bell Labs crowd was already highly skeptical of dynamic linking. See Rob Pike's opinion here: http://harmful.cat-v.org/software/dynamic-linking/
I say it's a hunch, but I think Russ Cox's following comments pretty much demonstrate this attitude against GNUisms and BSDisms: https://github.com/golang/go/issues/2096#issuecomment-660578... https://news.ycombinator.com/item?id=9207316
On the other hand, Russ clearly goes on to say they designed the flags not based on Plan 9 (which only had short single-letter flags), but on Google's gflags library: https://github.com/golang/go/issues/2096#issuecomment-660578...
In short, it's probably both:
- Innate distrust of all things BSD/GNU meant that the original Go team didn't feel they have to honor the established tradition. Just like dynamic linking, they believed that if there is something that GNU does wrong, they don't need to follow it just for the sake of keeping compatibility.
- Positive experience using gflags convinced the team that the gflags approach (single-dash long flags) is the best one.
I personally think they were wrong here. As Russ Cox himself clearly stated in response to all requests for fixing go flags: there are many libraries out there who implement GNU-style flags. What happened in practice is that most Go developers voted with their feet and chose a third-party flag module (even Google's own Kubernetes is using spf13/cobra). In the end, the Go flags package just ended up causing more confusion and didn't solve any of the problems (perceived or real) with GNU flags.
They were starting back from the 70s.
Also one more check for go being alt.history.java, this style is also the standard for Java tooling.
And Apple, I think.
Why do people not include that space? Certainly it's not to save the time of not hitting the spacebar, right?
(Tip: can hit “y” on GitHub to change the URL to a revision-based permalink)
Serving a static folder `/static` on port `3000` as user `static-user` and with cache headers set to 60 seconds would go like this:
thttpd -D -h 0.0.0.0 -p 3000 -d /static -u static-user -l - -M 60
Even if you've got Python lying around on every Ubuntu server, I still don't get why you wouldn't use something leaner to serve your static files, as long as it's easy to install/configure. Same goes for most of the runtimes in that list.I don't particularly care about what's least likely to fall over under sustained load or is suitable security wise to expose to the internet, because it's not going to have to deal with either of these things. Being "already installed" on the other hand is a big selling point.
Surprising not on Debian or Ubuntu AFAICT:
* https://packages.debian.org/search?keywords=thttpd
Though it does seem to have this from the same author:
* https://packages.debian.org/search?keywords=mini-httpd
* http://www.acme.com/software/mini_httpd/
There are times that I want to run Let's Encrypt that's not a full-time web server (SMTP, IMAP, etc), and it would be handy to spin up something ad hoc on tcp/80 to do the verification step and then stop it right after.
/* Read the MIME headers. */
while ( ( buf = bufgets( hc ) ) != (char*) 0 )
{
if ( buf[0] == '\0' )
break;
if ( strncasecmp( buf, "Referer:", 8 ) == 0 )
{
cp = &buf[8];
cp += strspn( cp, " \t" );
hc->referrer = cp;
}
else if ( strncasecmp( buf, "Referrer:", 9 ) == 0 )
{
cp = &buf[9];
cp += strspn( cp, " \t" );
hc->referrer = cp;
}
else if ( strncasecmp( buf, "User-Agent:", 11 ) == 0 )
{
cp = &buf[11];
cp += strspn( cp, " \t" );
hc->useragent = cp;
}
else if ( strncasecmp( buf, "Host:", 5 ) == 0 )
{
cp = &buf[5];
cp += strspn( cp, " \t" );
hc->hdrhost = cp;
Use perfect hash tables for known http headers, because they're perfect. while true; do cat index.html | nc -l 9999 -q 1; echo -e "\n---"; doneFor python3 this is easily remedied.
python -m http.server -b ::
On most OS configurations this will listen on both IPv4 and IPv6.Or for when you only need local access:
python -m http.server -b localhost[edit] ahh i see this is called out in the gist comments
[1] Emscripten's emsdk includes emrun, which actually serves WASM files with the correct MIME type out-of-the-box, unlike the python2 and python3 servers and most others.
I wonder how come CORS is such a misunderstood concept globally. It's a really simple concept in general, and understanding it will make a lot of your work as a frontend/full stack developer easier. Take a day and fully understand it, it'll pay off.
It’s not usually an issue for small stuff, but it does mean you can’t really use this snippet to serve big files for a lan, which is a bit of a surprise the first time you hit that limitation.
npx serve
is very easyDon't essentially all the options involve code downloaded from the internet? And you have to trust the source that it isn't malware or too buggy or insecure?
Are you making a case that the maintainers of this package aren't trustworthy? Or maybe the operators of npmjs.com?
I'm just not understanding the claim this is less secure than various other options.
This would make SQLite example supported: https://news.ycombinator.com/item?id=27016630
I know this because I have also been working on something using that magic sqlite-in-browser project :D
> socat TCP4-LISTEN:50000,fork EXEC:/usr/bin/ifconfig
> curl --http0.9 localhost:50000
Hmmm, does http v0.9 count?
I'd be interested in seeing if you can come up with a socat one-liner that works like a static file server. Would come in handy for many things, but I can't seem to figure out how to make it work.
This one might work https://github.com/avleen/bashttpd
> socat TCP4-LISTEN:8080 EXEC:/usr/local/bin/bashttpd
By that logic, apache is a one-liner.
The point is that there is a working http server already installed on your machine. And you just need to run this one simple, memorable command to use it.
Very useful if you just want to quickly copy some files from A to B in your LAN or WAN (wouldn't use it over Internet because not encrypted).
Edit: Someone has posted an Apache example: https://gist.github.com/willurd/5720255#gistcomment-3050599
[1] https://github.com/xonixx/serv
[2] https://medium.com/cmlteam/develop-a-utility-on-graalvm-cc16...
jbang webster@gunnarmorling
This launches Vert.x, publishing the current directory, via the JBang launcher. Source code is here if you want to see what you actually run: https://github.com/gunnarmorling/jbang-catalog/blob/master/w... devd .
[1]: https://github.com/cortesi/devdThat would be utterly convenient to quickly test multithread WASM applications...
I'm currently using ExpressJS for that, but it feels overkill..
But, if you still need it, the http-server program has a --cors flag to enable wildcard CORS.
There are lots of ways around this (put the files in your static folder, embed it into the file you're debugging, use a library which provides mock data, probably more), but it's not inconceivable to just want to be able to point the 'api' configuration param to localhost on a different port so you can just feed it json files from a directory that already has the data you want.
[1] https://github.com/tngranados/dotfiles/blob/0ebdc12f2454061a...
You could do `npx http-server` I believe.
$ ruby -r webrick/https -e "WEBrick::HTTPServer.new(Port: 9001, DocumentRoot: '.', SSLEnable: true, SSLCertName: [%w[CN localhost]]).start"https://www.betterhostreview.com/turn-on-iis-windows-10.html
nghttpd -v -d /home/user/www -a 127.0.0.1 443 /home/user/demoCA/serverkey.pem /home/user/demoCA/servercert.pem $ sthttpd/sbin/thttpd -i thttpd.pid -l `pwd`/access.log -p 8080 -c '/bin/*'Caddy works well and is easy to use and could replace most of these examples, not only for development but for production usage too.
Otherwise go for nginx/apache. Learn the config syntax once, get lifetime worth of value :)
sudo redbean.com -dp80 -L/var/log/redbean.log -P/var/run/redbean.pid -U65534 -G65534 -vvvvmbagIt should be trivial to write a shell script or alias that templates `root $(pwd);` and invokes `nginx -c /tmp/nginx.conf`
Nginx? Really? "One" thing? Try running `./configure --help` in the Nginx source dir...