Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Erro no cors RateLimit #181

Closed
fera765 opened this issue Mar 21, 2021 · 3 comments
Closed

Erro no cors RateLimit #181

fera765 opened this issue Mar 21, 2021 · 3 comments
Labels
invalid This doesn't seem right

Comments

@fera765
Copy link

fera765 commented Mar 21, 2021

RTK query problem

Inside the api I have the cors imported from the state with app.use(cors ()), but still giving this same error ..

I also made the configuration inside the RTK header

prepareHeaders: (headers, { getState }) => {
      headers.set('Access-Control-Allow-Origin', '*');
      headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT,PATCH, DELETE, OPTIONS');
    return headers;
  },

Access to fetch at 'http://localhost:3333/post/view/5c42f13a-2456-4b1a-9209-d87778303c22' from origin 'http://localhost:3000' has been blocked by CORS policy: 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.
fetchBaseQuery.ts:30 GET http://localhost:3333/post/view/5c42f13a-2456-4b1a-9209-d87778303c22 net::ERR_FAILED

@msutkowski
Copy link
Member

Hi there,

Those headers shouldn't be inside of prepareHeaders. You should only need to include credentials for authenticated endpoints from a client perspective.

Double check your server configuration and make sure you can hit your api with a tool like insomnia.rest or postman.

Additional reading: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

@fera765 fera765 changed the title Error in the cors Erro no cors RateLimit Mar 21, 2021
@fera765
Copy link
Author

fera765 commented Mar 21, 2021

Hi there,

Those headers shouldn't be inside of prepareHeaders. You should only need to include credentials for authenticated endpoints from a client perspective.

Double check your server configuration and make sure you can hit your api with a tool like insomnia.rest or postman.

Additional reading: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

I was able to debug the application, and I was able to identify that the error is because of RateLimit

@fera765
Copy link
Author

fera765 commented Mar 21, 2021

Too many requests per second are blocking, and my server is blocking...
These settings are inside my API

import { RateLimiterRedis } from 'rate-limiter-flexible';

const redisClient = redis.createClient({
  host: process.env.REDIS_HOST,
  port: Number(process.env.REDIS_PORT),
  password: process.env.REDIS_PASS,
});

const rate = new RateLimiterRedis({
  storeClient: redisClient,
  keyPrefix: 'middleware',
  points: 5,
  duration: 1,
});

is it wrong configuration, inside RTK-Query?

@msutkowski msutkowski added the invalid This doesn't seem right label Mar 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants