Jay Taylor's notes

back to listing index

Big list of http static server one-liners · GitHub

[web search]
Original source (gist.github.com)
Tags: one-liners webserver gist.github.com
Clipped on: 2024-07-08

Skip to content
Image (Asset 1/96) alt= npx servor <root> <fallback> <port>
https://www.npmjs.com/package/servor

Image (Asset 2/96) alt= Anyone know how to do it with elixir?

@SBoteroP You can do it in the following way:
https://gist.github.com/willurd/5720255?permalink_comment_id=2361144#gistcomment-2361144

Image (Asset 3/96) alt= source: https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/

The following libraries are no longer bundled gems or standard libraries. Install the corresponding gems to use these features.

  • sdbm
  • webrick
  • net-telnet
  • xmlrpc
Image (Asset 4/96) alt= net-http is only a client. Since the webrick removal there is no built-in web server included with ruby.

RealYukiSan commented Feb 24, 2024
edited

@wtarreau says:

once most universal

not included on arch linux fresh installation

RealYukiSan commented Feb 24, 2024

is there any command that work on fresh installation of linux system? (no need to install additional package)

nilslindemann commented Feb 24, 2024
edited

@RealYukiSan on Linux Mint, Python is installed by default, so $ python -m http.server 8000 works. But Arch seems not to have Python. On Arch, You may try things like this, using netcat. Edit: But I am not sure if that is installed on Arch.

wtarreau commented Feb 24, 2024

is there any command that work on fresh installation of linux system? (no need to install additional package)

Well, in this case on x86 you can use some asm servers such as https://github.com/margaretbloom/nash-f/ and just emit their tiny code like this:

base64 -d <<< "H52Qf4owMRKgIICDCBEKADAAQACEYAARQEAjocWDFUE4BIDC4sODYCBKRBBxIiGEJw8eQAjhosuDagyoCaBGQIxtswKg84FQDQQ04EZCmSUA3Yuef67MIoCuRE8AagAoLYAuA0IoiYbFAAaLQC5fI2NIkyWiGaAtsAyYXbdtKywzjZiQIGB2EZ+5wggAQEKFCpQXMVzAACEDxuAnSxooUMwDTQwfSMqwYfMmBI8Xjn0sFAEG" | gzip -cd > httpd ; chmod 755 httpd; ./httpd

Nothing to install except making sure to have base64 and gzip. Or if you really want to have nothing but chmod, you can do that:

echo -ne 'x7fELFx01x01x01000000000x020x030x01000x60x80x04x08x3400000000000x340x200x010x2800000x01000x60000x60x80x04x08x60x80x04x08x84000x84000x07000x10000000000000000x6ax06x6ax01x6ax02x31xdbxb3x01xe8x3e000x6ax10x68xe0x80x04x08x50xb3x02xe8x2f000x6ax7fx57xb3x04xe8x25000x6a0x6a0x57xb3x05xe8x19000x50x89xc3x31xc0xb0x04xb9xbex80x04x08x31xd2xb2x22xcdx80x5bxb0x06xcdx80xebxdbx31xc0xb0x66x8dx4cx24x04xcdx80x8bx7cx24x04xc2x040HTTP/1.0 200 OKrnrn<h1>Hello!</h1>x020x22x60' > httpd; chmod 755 httpd; ./httpd

With some training, you could even learn it to send it only from memory, that could be fun.

mieszko4 commented Feb 25, 2024
edited

Well, in this case on x86 you can use some asm servers such as https://github.com/margaretbloom/nash-f/ and just emit their tiny code like this:

RealYukiSan commented Feb 27, 2024

Thanks for the tips @wtarreau @nilslindemann !

With some training, you could even learn it to send it only from memory, that could be fun.

What do you mean by 'send it only from memory'? did you mean execute the instruction without store it to file?

wtarreau commented Feb 27, 2024

I mean memorize it entirely in your head, like people remember Pi, so that you don't have to store it anywhere. It's only 228 bytes after all :-)

RealYukiSan commented Feb 27, 2024

That's sounds cool! did you wrote it by yourself? I tried to understand the code by running it on gdb, but unfortunately the file not contain any symbol :-(

RealYukiSan commented Feb 27, 2024
edited

Ah, my bad. I didn't notice that you provided a reference to the source code.

DestyNova commented Mar 24, 2024

crystal eval 'require "http/server"; server = HTTP::Server.new( [HTTP::LogHandler.new, HTTP::StaticFileHandler.new("./")] ); server.bind_tcp "127.0.0.1", 8080; server.listen'

That one doesn't seem to work; the downloads get interrupted every time with no stacktrace (Crystal 1.9.2).

air3ijai commented Jun 26, 2024

Using Nginx docker image we can set a simple custom index page

# Run
docker run 
  --rm 
  --name nginx 
  --publish 80:80 
  nginx 
  bash -c "echo host-a >/usr/share/nginx/html/index.html; nginx -g 'daemon off;'"
# Check
while true; do curl localhost; sleep 1; done
host-a
host-a
host-a

mwilsoncoding commented Jul 5, 2024
edited

Update for Elixir (1.17.1):

elixir --no-halt -e 'Application.start(:inets); :inets.start(:httpd, port: 8000, server_root: ~c".", document_root: ~c"./doc", server_name: ~c"localhost", mime_types: [{~c"html",~c"text/html"},{~c"htm",~c"text/html"},{~c"js",~c"text/javascript"},{~c"css",~c"text/css"},{~c"gif",~c"image/gif"},{~c"jpg",~c"image/jpeg"},{~c"jpeg",~c"image/jpeg"},{~c"png",~c"image/png"}])'

This example uses the doc directory for a quick way to locally host/view docs generated with ExDoc.

Here's the more readable version of the string being eval'd, shown as an iex session:

iex(1)> Application.start(:inets)
:ok
iex(2)> :inets.start(:httpd,
...(2)>   port: 8000,
...(2)>   server_root: ~c".",
...(2)>   document_root: ~c"./doc",
...(2)>   server_name: ~c"localhost",
...(2)>   mime_types: [
...(2)>     {~c"html", ~c"text/html"},
...(2)>     {~c"htm", ~c"text/html"},
...(2)>     {~c"js", ~c"text/javascript"},
...(2)>     {~c"css", ~c"text/css"},
...(2)>     {~c"gif", ~c"image/gif"},
...(2)>     {~c"jpg", ~c"image/jpeg"},
...(2)>     {~c"jpeg", ~c"image/jpeg"},
...(2)>     {~c"png", ~c"image/png"}
...(2)>   ]
...(2)> )
{:ok, #PID<0.118.0>}

^ woops- just found this

It's not technically a one-liner, but my use-case is better solved with:

mix do hex.docs fetch + docs && cp -r doc "${HEX_HOME}/docs/hexpm/${OTP_APP}/${OTP_APP_VERSION}" && mix hex.docs offline "${OTP_APP}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Footer

© 2024 GitHub, Inc.

Footer navigation