Home > database >  Perl/Raku succinct webserver one-liner?
Perl/Raku succinct webserver one-liner?

Time:06-21

Are there any concise one-liners for quick serving of pages or directories if no index.html? Something like this:

python3 -m http.server

Couldn't find a Raku one-liner.
Compare Perl ones, taken from https://gist.github.com/willurd/5720255 and https://github.com/imgarylai/awesome-webservers :

plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root=>".");' -p 8000
perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>8000); $s->mount("/"=>{path=>"."}); $s->start'

Install them prior to use (no additional installs with Python):

cpan Plack
cpan HTTP::Server::Brick

Plack pulls in a gajillion of dependencies so I didn't proceed with installation, and HTTP::Server::Brick doesn't install on my machine as its tests fail.

Both Perl and Raku are generally considered to be good in one-liners, and are meant to deliver DWIM: "try to do the right thing, depending on the context", "guess ... the result intended when bogus input was provided"

So I'd expect them - especially modern and rich Raku - to provide a webserver one-liner on par in simplicity with Python.
Or have I missed something?
If the feature lacks, is it planned?
If lacks and not-to-be-implemented, why?

CodePudding user response:

I like http_this (https_this is also available).

There's an annoying shortcoming in that it doesn't currently support index.html - but I have a pull request pending to fix that.

On the other hand, these programs rely on Plack, so maybe you'd rather look elsewhere.

CodePudding user response:

Raku Cro needs one line to install:

zef install --/test cro

And then one to setup and run:

cro stub http hello hello && cro run

From https://cro.services/docs/intro/getstarted

Let's say you want to serve all the files in a project subdirectory e.g. hello/httpd, then tweak the standard hello/lib/Routes.pm6 file to this:

  1 use Cro::HTTP::Router;
  2 
  3 sub routes() is export {
  4     route {
  5         get -> *@path {
  6             static 'httpd', @path;
  7         }
  8     }
  9 }

cro run looks for file changes and will auto restart the server

index.html works fine

I suggest a symbolic link ln -s if your dir is outside the project tree

  • Related