perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.64k stars 1.56k forks source link

CORS with static files #1066

Open zd-project opened 5 years ago

zd-project commented 5 years ago

So I came a cross the similar situation to this question #973. I want to serve up some static files via sparkjava, with CORS enabled. But it seems that the "before" filter only works with specified routes in code but not with static files. I'm wondering how I should enable CORS on static files as well. Thanks.

zd-project commented 5 years ago

I'm able to solve this issue with this snippet https://gist.github.com/saeidzebardast/e375b7d17be3e0f4dddf#gistcomment-2704256 Spark.staticFiles.header("Access-Control-Allow-Origin", "*"); Would be helpful to specify so in the documentation.