Last active
December 19, 2017 20:54
-
-
Save preaction/a240c2bcf38883afce95a47e8b5179b3 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; | |
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