1

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

Pabort
  • 348
  • 1
  • 11

1 Answers1

0

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
  • I tried your answer but still get an error. My console says: "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled." – Pabort May 05 '22 at 23:55
  • i just realized i swapped the properties and corrected the answer accordingly, btw your error states that you indeed need to set the one containing Access-Control-Allow-Origin. – Manuel Materazzo May 06 '22 at 08:04
  • Also make sure to be using the latest version of bucket4j, or these options probably won't work. – Manuel Materazzo May 06 '22 at 08:26
  • Sorry, i'm on the junior side of development, what are and params? I'm looking at them at my spring server and don't find anything like that. – Pabort May 06 '22 at 15:39