Skip to content

Instantly share code, notes, and snippets.

@preaction
Last active December 19, 2017 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save preaction/a240c2bcf38883afce95a47e8b5179b3 to your computer and use it in GitHub Desktop.
Save preaction/a240c2bcf38883afce95a47e8b5179b3 to your computer and use it in GitHub Desktop.
use Mojolicious::Lite;
use Mojo::Asset::File;
use Alien::SwaggerUI;
use File::Spec::Functions qw( catfile );
get '/docs/*path' => { path => 'index.html' }, sub {
my ( $c ) = @_;
# Redirect so that trailing / helps browser build URLs and
# we have our spec loaded. Can't make its own route because
# the trailing `/` is optional in Mojolicious's route
if ( !$c->req->url->path->trailing_slash && $c->req->url->path eq '/docs' ) {
$c->req->url->path->trailing_slash(1);
$c->req->url->query( url => '/v3' );
return $c->redirect_to( $c->req->url );
}
my $path = catfile( Alien::SwaggerUI->root_dir, $c->stash( 'path' ) );
my $file = Mojo::Asset::File->new( path => $path );
$c->reply->asset( $file );
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment