Skip to content

Commit

Permalink
Allow swagger to reside behind a reverse proxy
Browse files Browse the repository at this point in the history
proposal to fix khrt#101
  • Loading branch information
hidden-primary-net committed Jun 22, 2020
1 parent 75c16bd commit 8c4b9d8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/Raisin/Plugin/Swagger.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,22 @@ sub _spec_20 {
: qw(application/x-yaml application/json);

my $base_path = $req->base->as_string;
$base_path =~ s#http(?:s?)://[^/]+##msix;
### Respect proxied requests
# A proxy map is used to fill the "basePath" attribute.
my $_base = $req->env->{HTTP_X_FORWARDED_SCRIPT_NAME} || q(/);
$base_path =~ s#http(?:s?)://[^/]+/#$_base#msix;

$DEFAULTS{consumes} = \@content_types;
$DEFAULTS{produces} = \@content_types;

my %spec = (
swagger => '2.0',
info => _info_object($app),
host => $req->env->{SERVER_NAME} || $req->env->{HTTP_HOST},
### Respect proxied requests
# The frontend hostname is used if set.
host => $req->env->{HTTP_X_FORWARDED_HOST}
|| $req->env->{SERVER_NAME}
|| $req->env->{HTTP_HOST},
basePath => $base_path,
schemes => [$req->scheme],
consumes => \@content_types,
Expand Down

0 comments on commit 8c4b9d8

Please sign in to comment.