Sinatra公开文件夹的Sinatra访问控制允许来源 [英] Sinatra access-control-allow-origin for sinatra public folder
问题描述
如何设置Sinatra,使公用文件夹
中的静态文件与响应Access-Control-Allow-Origin =*一起返回?
How do I set up Sinatra so that static files in the public folder are returned with the response Access-Control-Allow-Origin = "*" ?
推荐答案
请看这里: Sinatra OPTIONS HTTP动词。它现在在sinatra中实现了,所以你不必在它周围进行破解。
Have a look at this question here: Sinatra OPTIONS HTTP Verb. It's implemented in sinatra now so you don't have to hack around it.
如果这无助于看看这篇博文:与Sinatra的跨源资源共享及其在github的回购: sinatra-corss_origin
If that doesn't help take a look at this blog post: Cross Origin Resource Sharing with Sinatra, and its repo at github: sinatra-corss_origin
虽然最简单的做法应该是加上这个:
Although the simplest way to do it should work just by adding this:
response['Access-Control-Allow-Origin'] = 'http://whatever.org'
在路线中的返回值之前。
before the return value in your route.
这篇关于Sinatra公开文件夹的Sinatra访问控制允许来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!