Created
February 25, 2020 20:20
-
-
Save jberger/0009fafb7b3b81798d122fdd2bcfdd44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite -signatures; | |
use CommonMark; | |
# server markdown from markdown/ within app's home | |
my $root = app->home->child('markdown'); | |
get '/*file' => sub ($c) { | |
#TODO handle traversal attacks | |
my $path = $root->child($c->stash('file')); | |
return $c->reply->not_found | |
unless -f $path; | |
$c->render( | |
text => CommonMark->markdown_to_html($path->slurp), | |
format => 'html', | |
); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment