如何启用CORS的催化剂

问题描述 投票:1回答:1

有一个Perl的催化剂的应用,其产生JSON,我需要阅读使用jQuery的HTML页面内的JSON内容,通过Apache服务器提供。这两个应用程序,催化剂和Apache在同一主机上运行。

当我从Apache的访问URL的催化剂我得到的错误

Access to XMLHttpRequest at 'http://localhost:3000/abc/json_list' from origin 'http://localhost:8888' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

正如我在许多主题红色,头(或以上)必须设置。在这种情况下,催化剂必须设置,但我不知道怎么办。

任何提示?

apache perl cors catalyst
1个回答
3
投票

催化剂允许您使用the header method on the response object设置响应头。

$c->res->header( "Access-Control-Allow-Origin" => "http://localhost:8888" );

考虑使用一个控制器的sub autousing现有middleware如果您有需要通过CORS提供允许多个端点。

© www.soinside.com 2019 - 2024. All rights reserved.