CORS issue: Request header field x-msw-request-id is not allowed by Access-Control-Allow-Headers
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0.36.2 |
google chrome | 95.0.4638.69 |
Ubuntu | 20.0.4 |
Request handlers
const setup = () => {
if (typeof window === 'undefined') {
const { server } = require('./server');
server.listen({ onUnhandledRequest: 'bypass' });
} else {
const { worker } = require('./browser');
worker.start({ onUnhandledRequest: 'bypass' });
}
};
export default setup;
Server setup
import { rest } from 'msw';
import { setupServer } from 'msw/node';
const server = setupServer([
rest.get('*/house/:externalId/info', (req, res, ctx) =>
res(ctx.json(mock.house)),
),
rest.get('*/house-enums', (req, res, ctx) =>
res(ctx.json(enumMock.houseEnums)),
),
rest.get('*/bff/sales-flow/:salesFlowId/ccv-card', (req, res, ctx) =>
res(ctx.json(ccvMock.validCCVData)),
),
rest.patch('*/bff/sales-flow/:salesFlowId/ccv-card', (req, res, ctx) =>
res(ctx.status(200)),
),
rest.get('*/ccv-enums', (req, res, ctx) => res(ctx.json(ccvMock.ccvEnums))),
rest.get('*/sales-flow/:salesFlowId/diligence', (req, res, ctx) =>
res(ctx.json(diligenceResponseMock.diligenceData)),
),
]);
export { server, rest };
Actual request
This request is a bypassed one made by an authentication library that we use internally.
The fetch to https://sso.keycloak.com.br/auth/realms/forno/protocol/openid-connect/token
passes a code received in a previous request and a redirect url and expects the authentication token as a response.
Current behavior
Receiving following error on console
Access to XMLHttpRequest at 'https://sso.keycloak.com.br/auth/realms/forno/protocol/openid-connect/token' from origin 'http://vendas.dev.quintoandar.com.br' has been blocked by CORS policy: Request header field x-msw-request-id is not allowed by Access-Control-Allow-Headers in preflight response.
Expected behavior
Request is successfully bypassed without CORS issue. Is there a way to exclude this header for bypassed requests?
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Request header field Access-Control-Allow-Headers is not ...
Request header field Content-Type is not allowed by Access-Control-Allow-Headers. So I googled the error and added the headers: $http.post($rootScope.URL, { ...
Read more >CORS error: Request header field Authorization is not allowed ...
The headers the browser sends with the request have to all be specified in the server's Access-Control-Allow-Headers response header. You can view the...
Read more >Access-Control-Allow-Headers - HTTP - MDN Web Docs
This header is required if the request has an Access-Control-Request-Headers header. Note: CORS-safelisted request headers are always allowed ...
Read more >Fixing Common Problems with CORS and JavaScript
If the JavaScript fetch request specifies cors a request header will be ... field x-token is not allowed by Access-Control-Allow-Headers in ...
Read more >Troubleshoot CORS errors from API Gateway - Amazon AWS
I get the error "No 'Access-Control-Allow-Origin' header is present on the requested resource" when I try to invoke my Amazon API Gateway ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Figured out it was related to a misconfiguration of the whole parameters object. Related to storybook itself. So luckily it is not related to MSW itself.
I see. This doesn’t look like the error related to the
x-msw-request-id
issue. We’d see that header being rejected by the server. What we see in the error above is that endpoint X doesn’t allowlocalhost
like an origin. Sorry, I don’t have enough context to suggest anything meaningful right now. I’d ask you to create a reproduction repository for this and submit a new issue.I can only propose to double-check that MSW is enabled in Storybook (you see the console log message). Double-check with the add-on docs to be sure.