问题
How to enable CORS in vespa? I want to deploy my API's to swagger UI but due to CORS disbled in vespa, I am unable to do this. Is there any way to enable CORS in vespa or How should I use API's in swagger to use it? Please help.
回答1:
Vespa does not come with built-in CORS support. You'll have to implement the CORS logic yourself as JDisc security filters (http-server-and-filters.html, services-http.html#filter).
The Vespa source code contains a set of CORS filters that can be used as inspiration. You can technically use them, but they are not public API and can be changed/removed in the future.
You will need two filters:
- A request filter handling CORS preflight HTTP requests
- A response filter that appends CORS headers to HTTP responses
Note that the response filters are not invoked if a request filter returns a response. Any other JDisc filters in your application must therefore include the CORS headers when they return a response.
See http-server-and-filters.html#set-up-filter-chains on how to configure request/response filter chains.
来源:https://stackoverflow.com/questions/53810631/enable-cors-in-vespa