如何在 DIVSHOT 上启用 CORS?
How to enable CORS on DIVSHOT?
我一直在努力使用 Access-Allow-Control-Origin
,我正在使用 Divshot。在我的移动应用程序中,我正在显示 WordPress 帐户的帖子,当我在浏览器中测试我的应用程序时,我可以看到这些帖子,但是一旦我在 Chrome 中打开应用程序移动版,我就看不到这些帖子.据我所见,有人有同样的问题,所以我需要在Divshot配置文件中使用CORS。
在 Divshot 页面,this is what they say,但我不知道如何在我的应用程序中做到这一点
Custom Headers
If you need to set custom response headers for specific routes,
you can use the headers key in your configuration file:
{
"headers": {
"/cors-stuff/**": {
"Access-Control-Allow-Origin": "*"
},
"/scripts/**": {
"content-type": "text/javascript"
}
}
}
This can be useful for applying a content security policy, enforcing a different content-type, enabling cross-origin resource sharing (CORS), and more.
这就是我的配置文件中的内容
{
"name": "urbanetradio",
"root": "www",
"clean_urls": true,
"error_page": "error.html",
"headers": {
"Access-Control-Allow-Origin": "*",
"/js/**": {
"content-type": "text/javascript"
}
}
}
可是我还是没有什么好结果
以防万一有人想知道,在执行请求时你必须发送更多参数,看看这个例子,我现在已经开始工作了
getBlogs: function($scope) {
$scope.postsURL = 'http://urbanetradio.com/wp-json/posts?_jsonp=JSON_CALLBACK';
$http.jsonp($scope.postsURL).success(function(data, status, headers, config) {
console.log(config);
$scope.posts = data;
}).error(function(data, status_headers, config) {
console.log('error');
});
}
我一直在努力使用 Access-Allow-Control-Origin
,我正在使用 Divshot。在我的移动应用程序中,我正在显示 WordPress 帐户的帖子,当我在浏览器中测试我的应用程序时,我可以看到这些帖子,但是一旦我在 Chrome 中打开应用程序移动版,我就看不到这些帖子.据我所见,有人有同样的问题,所以我需要在Divshot配置文件中使用CORS。
在 Divshot 页面,this is what they say,但我不知道如何在我的应用程序中做到这一点
Custom Headers
If you need to set custom response headers for specific routes,
you can use the headers key in your configuration file:
{
"headers": {
"/cors-stuff/**": {
"Access-Control-Allow-Origin": "*"
},
"/scripts/**": {
"content-type": "text/javascript"
}
}
}
This can be useful for applying a content security policy, enforcing a different content-type, enabling cross-origin resource sharing (CORS), and more.
这就是我的配置文件中的内容
{
"name": "urbanetradio",
"root": "www",
"clean_urls": true,
"error_page": "error.html",
"headers": {
"Access-Control-Allow-Origin": "*",
"/js/**": {
"content-type": "text/javascript"
}
}
}
可是我还是没有什么好结果
以防万一有人想知道,在执行请求时你必须发送更多参数,看看这个例子,我现在已经开始工作了
getBlogs: function($scope) {
$scope.postsURL = 'http://urbanetradio.com/wp-json/posts?_jsonp=JSON_CALLBACK';
$http.jsonp($scope.postsURL).success(function(data, status, headers, config) {
console.log(config);
$scope.posts = data;
}).error(function(data, status_headers, config) {
console.log('error');
});
}