Last Updated: February 25, 2016
·
543
· ddossot

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