Mojo one-liner to serve directory #2299
Unanswered
ThisUsedToBeAnEmail
asked this question in
Q&A
Replies: 2 comments 1 reply
-
|
My use-case is here, it's in a Makefile hence the $$ - https://github.com/ThisUsedToBeAnEmail/Funky-Frame/blob/main/Makefile |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
https://metacpan.org/pod/App::SimpleHTTPServer is one option, largely based on https://metacpan.org/pod/Mojolicious::Plugin::Directory. I am not aware of similar directory index logic in core. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I think other solutions exist on CPAN and i could just write my own but I'm just wondering if anything built in Mojo dist itself that i'm missing.
My current solution is:
perl -Mojo -e 'a->static->paths->[0]=f;a->hook(before_dispatch=>sub{my$$c=shift;my$$p=$$c->req->url->path->to_string;$$p.="/"unless$$p=~/\.\w+$$/||$$p=~m|/$$|;$$p.="index.html"if$$p=~m|/$$|;$$c->req->url->path($$p)});a->start' daemon -l http://0.0.0.0:8000so /playground will render /playground/index.html.
Can this be done in a more concise way? It would be cool if I could just type perl -
Mojo -e 'a->serve->start' daemon -l ...- or something but I guess that would require internal changes and maybe my example above is not what 'everbody' would want.Beta Was this translation helpful? Give feedback.
All reactions