Serve static files over HTTP with CORS support
Using PSGI/Plack to quickly bootstrap a web server to serve static files with CORS headers support enabled.
Install Plack and the CORS middleware (sudo
if you want to install globally):
cpanm Task::Plack
cpanm Plack::Middleware::CrossOrigin
Then create configuration file (say server.psgi
) in the directory whose files you want to serve, with this content:
use Plack::Builder;
use Plack::App::File;
my $app = Plack::App::File->new(root => "$ENV{PWD}");
builder {
enable 'CrossOrigin', origins => '*';
$app;
};
Finally, run: plackup server.psgi
Written by David Dossot
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Perl
Authors

janosgyerik
25.21K

Jean-Remy Duboc
12.28K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#