Skip to content

Instantly share code, notes, and snippets.

@sng2c
Last active August 29, 2015 14:24
Show Gist options
  • Save sng2c/b3444121b1f2eefddf3d to your computer and use it in GitHub Desktop.
Save sng2c/b3444121b1f2eefddf3d to your computer and use it in GitHub Desktop.
SCRIPT_NAME 가 더 일반적인듯..
#!/usr/bin/env perl
use Mojolicious::Lite;
use Scalar::Util 'weaken';
hook( before_dispatch => sub {
use Data::Dump;
my $self = shift;
my $uri = $self->req->headers->header('SCRIPT_NAME');
my $base = Mojo::URL->new($uri);
dd $self->req->url->path;
my $raw_path = $self->req->url->path;
say $raw_path;
$raw_path =~ s/^$uri//;
say $raw_path;
# say $raw_path;
$self->req->url->path($raw_path);
$self->req->url->base($base) if $uri;
});
# Upload form in DATA section
get '/' => sub {
my $c = shift;
$c->render('index');
};
# Streaming multipart upload
post '/upload' => {text => 'Upload was successful.'};
app->start;
__DATA__
@@ index.html.ep
<!DOCTYPE html>
<html>
<head><title>Streaming multipart upload</title></head>
<body>
%= form_for 'upload' => (enctype => 'multipart/form-data') => begin
%= file_field 'example'
%= submit_button 'Upload'
% end
</body>
</html>
location /mojo {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header SCRIPT_NAME /mojo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment