Refactoring Dancer app - use the before hook
header 'Content-Type' => 'application/json';
header 'Access-Control-Allow-Origin' => '*';
hook before => sub {
if (request->path =~ m{^/api/}) {
header 'Content-Type' => 'application/json';
}
if (request->path =~ m{^/api/v2/}) {
header 'Access-Control-Allow-Origin' => '*';
}
};