【发布时间】:2019-12-12 21:01:29
【问题描述】:
我正在尝试使用 Coldfusion 组件构建 REST API,但我不知道如何启用 CORS。我正在使用 IIS 10 和 ColdFusion 2016。我在 IIS 中找不到任何地方来按照谷歌上的说明配置 CORS,而且我在 CF 管理设置下看不到任何地方来启用 CORS,所以我想我会尝试在我的API 而不是在每个环境中摆弄配置,我将它部署到 (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 function onSessionEnd(sessionScope, applicationScope) {
return;
}
}
</cfscript>
【问题讨论】:
标签: rest coldfusion cors