Hello all,
I'm trying to use Mongrel2 as a backend server from where several web sites
will fetch data trough clients making ajax calls. To make this possible I
need to be able to set the Access-Control-Allow-Origin HTTP header as
Cross-Origin Resource Sharing dictates.
Is it possible to add it to every response, like in apache when I declare
"Header set Access-Control-Allow-Origin *" in the httpd.conf?
Or should I set in every handlers something like a
response.headers.set('Header set Access-Control-Allow-Origin', '*')?
Should I put it on req.headers.get() instead?
Thanks!
Gustavo G
Hello, > I'm trying to use Mongrel2 as a backend server from where several web sites > will fetch data trough clients making ajax calls. To make this possible I > need to be able to set the Access-Control-Allow-Origin HTTP header as > Cross-Origin Resource Sharing dictates. > > Is it possible to add it to every response, like in apache when I declare > "Header set Access-Control-Allow-Origin *" in the httpd.conf? > Or should I set in every handlers something like a > response.headers.set('Header set Access-Control-Allow-Origin', '*')? > Should I put it on req.headers.get() instead? Yes, you need to output the header yourself at the handler level. The way you do it will depend of the language/framework you use. If you use Python/Django you could just use a middleware to set the header for each answer. Usually the frameworks are pretty good at providing a way to modify all the outgoing answers in a systematic way. loïc -- Indefero - Project management and code hosting - http://www.indefero.net Photon - High Performance PHP Framework - http://photon-project.com Céondo Ltd - Web + Science = Fun - http://www.ceondo.com
Thanks Loic.
I just had to put
conn.reply_http(req, response ,200,"OK",{"Access-Control-Allow-Origin":
"*"})
in the handler.
Long live mongrel2, zeromq!
Cheers,
Gustavo g
On 23/09/11 14:49, Loic d'Anterroches wrote:
> Hello,
>
>> I'm trying to use Mongrel2 as a backend server from where several web sites
>> will fetch data trough clients making ajax calls. To make this possible I
>> need to be able to set the Access-Control-Allow-Origin HTTP header as
>> Cross-Origin Resource Sharing dictates.
>>
>> Is it possible to add it to every response, like in apache when I declare
>> "Header set Access-Control-Allow-Origin *" in the httpd.conf?
>> Or should I set in every handlers something like a
>> response.headers.set('Header set Access-Control-Allow-Origin', '*')?
>> Should I put it on req.headers.get() instead?
> Yes, you need to output the header yourself at the handler level. The
> way you do it will depend of the language/framework you use. If you use
> Python/Django you could just use a middleware to set the header for each
> answer. Usually the frameworks are pretty good at providing a way to
> modify all the outgoing answers in a systematic way.
>
> loïc
>
> --
> Indefero - Project management and code hosting - http://www.indefero.net
> Photon - High Performance PHP Framework - http://photon-project.com
> Céondo Ltd - Web + Science = Fun - http://www.ceondo.com