Open istvan-ujjmeszaros opened 6 years ago
Hi,
We are trying to enable CORS on our h2o server. We tried to add the above mentioned header in the h2o.conf file at multiple levels (global, host and path), but still it is not working. Can you please specify where this line needs to be added? Also it would be really helpful if you can provide an example config file.
Thanks
@daymakhan23 If I'm reading the configs right (at least for the h2o wave server) then there's a flat file with all the required additional headers as documented in https://wave.h2o.ai/docs/configuration#H2O_WAVE_HTTP_HEADERS_FILE.
But I think we might be talking about two different h2o servers here and looking over the other one; adding the headers.add line to the hosts block should work. https://h2o.examp1e.net/configure/headers_directives.html
listen:
port: 80
hosts:
"myhost.example.com":
listen: &listen_ssl
port: 443
ssl:
certificate-file: /path/to/certificate-file
key-file: /path/to/key-file
listen:
<<: *listen_ssl
type: quic
header:
add: "Access-Control-Allow-Origin: *"
paths:
/:
file.dir: /path/to/the/public-files
user: nobody
access-log: /path/to/the/access-log
error-log: /path/to/the/error-log
pid-file: /path/to/the/pid-file
The test file pretty much confirms its usage: https://github.com/h2o/h2o/blob/b311c049d433a421e00bc52c442d47f373b949a1/t/50headers.t#L14
You can add header with
header.add: "Access-Control-Allow-Origin: *"
More info in the documentation: https://h2o.examp1e.net/configure/headers_directives.html