我正在尝试使用 Coldfusion 组件构建 REST API,但我不知道如何启用 CORS。我正在使用 IIS 10 和 ColdFusion 2016。按照 google 上的说明,我无法在 IIS 中找到任何位置来配置 CORS,并且在 CF 管理设置下没有看到任何地方可以启用 CORS,所以我想我会尝试在我的应用程序中启用 CORS。我将其部署到(qa、uat、prod),而不是在每个环境中摆弄配置。
这就是我的 application.cfc 当前的样子,您可以在 onRequestStart 中看到我正在尝试设置标头(我尝试过两种方法)
<cfscript>
component output="false" {
this.name = ....
public boolean function onApplicationStart() {\
restInitApplication( ... );
return true;
}
public void function onApplicationEnd(ApplicationScope) {
return;
}
public void function onMissingTemplate(targetPage) {
return;
}
public void function onRequestStart(targetPage) {
cfheader(name="Access-Control-Allow-Origin", value="*");
// i've also tried ...
GetPageContext().getResponse().addHeader("Access-Control-Allow-Origin","*");
}
public void function onSessionStart() {
return;
}
public void …Run Code Online (Sandbox Code Playgroud)