thomasp85 / fiery

A flexible and lightweight web server
https://fiery.data-imaginist.com
Other
240 stars 12 forks source link

Access-Control-Allow-Origin CORS problem #8

Closed Lchiffon closed 7 years ago

Lchiffon commented 7 years ago

fiery is awesome! It makes some project much more easy.

I'm using fiery with node: write a app and use node to fetch this. While, there is a CORS problem:

Chorme console:

XMLHttpRequest cannot load http://localhost:9123/XXXXXXXXXXX. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

I think it could be handled in the fiery, wondering if there is any method to set Access-Control-Allow-Origin in the header.

Lchiffon commented 7 years ago

Aoooooo~ I knew!

Add these to my response$headers can solve this problem!

response$headers <- list('Content-Type'='text/json',
                                  "Access-Control-Allow-Origin"="*",
                                  "Access-Control-Allow-Headers"="Content-Type,Content-Length, Authorization, Accept,X-Requested-With",
                                  "Access-Control-Allow-Methods"="PUT,POST,GET,DELETE,OPTIONS")