Using Rate Limiting doesn't add Header to response and gets CORS error in client

430 views Asked by At

I'm trying to adapt this tutorial to my server using the Bucket4j Spring Boot Starter. I'm using an application.properties file. I can limit the api queries with no problem, but the client doesn't get a 429 error, on the client I get a CORS error. I figure this is because I'm not adding a header to my server response when I'm limiting the api queries, but is there any way to add this throught the application.properties template?

On the official documentation there is a value called "bucket4j.filters[0].http-response-headers.<MY_CUSTOM_HEADER>=MY_CUSTOM_HEADER_VALUE" but I can't figure how to use it, did anybody use it?

Thanks

1

There are 1 answers

4
Manuel Materazzo On

You can avoid CORS errors by adding the proper header:

bucket4j.filters[0].http-response-headers.Access-Control-Allow-Origin="https://<clientUri>:<clientPort>"

and if you are using some form of authentication you may want to also add this:

bucket4j.filters[0].http-response-headers.Access-Control-Allow-Credentials=true