Live data from Hacker News

Web server in one line of bash

razvantudorica.com

21–30 of 69 posts

Re: Web server in one line of bash

#24

This seems to be straight from Wikipedia and then wrapped in a while loop: https://en.wikipedia.org/wiki/Netcat#Setting_up_a_one-shot_w... netcat's cool, but the post could've gone a bit further. If it's an intro "how to do this", maybe explain the moving parts for beginners?

[deleted]

Re: Web server in one line of bash

#26

If you have python, then these are really useful, just serves up the current directory. Python 2.x: python -m SimpleHTTPServer Python 3.x: python -m http.server 8000

Or for https (e.g. when developing for Chrome's speech recognition API):

    twistd --nodaemon web --path=. -c snakeoil.crt -k snakeoil.key --https=8443
And to generate a 100-year localhost key/cert for use with this:

    openssl genrsa -passout pass:dummy -out snakeoil.secure.key 1024
    openssl rsa -passin pass:dummy -in snakeoil.secure.key -out snakeoil.key
    openssl req -new -subj "/commonName=localhost" -key snakeoil.key -out snakeoil.csr
    openssl x509 -req -days 36500 -in snakeoil.csr -signkey snakeoil.key -out snakeoil.crt

Re: Web server in one line of bash

#29
post #25

If you have node-static installed. npm install -g node-static # serve up the current directory $ static serving "." at http://127.0.0.1:8080 More at https://github.com/cloudhead/node-static

Similarly, if PHP 5.4 (or greater) is installed:

    php -S 127.0.0.1:8080

Re: Web server in one line of bash

#30
post #29
post #25

If you have node-static installed. npm install -g node-static # serve up the current directory $ static serving "." at http://127.0.0.1:8080 More at https://github.com/cloudhead/node-static

Similarly, if PHP 5.4 (or greater) is installed: php -S 127.0.0.1:8080

This my defacto, PHP is installed on all the Linux servers I manage, mostly Debian/Ubuntu with DotDeb repos. You could probably get nc to pipe the output of php-cli for older PHP installs.

http://stackoverflow.com/questions/3940046/can-i-use-netcat-... seems to have a basic example.

Post reply on HN