When I configured cors: '*' in payload.config.ts, I still got a CORS error when accessing it with other ports. Can anyone please advise on how to solve this issue?
cors: '*',
rateLimit: {
trustProxy: true,
window: 2 * 60 * 1000, // 2 minutes
max: 2400, // limit each IP per windowMs
},
I have found a solution to fix the CORS issue, but it's not elegant. I believe the server.ts configuration not working should be considered a bug.The code is written in server.ts.
var cors = require('cors');
var corsOptions = {
origin: '*',
credentials: true,
optionsSuccessStatus: 200
}
app.use(cors(corsOptions));
it need run“yarn add cors” first,
Normally, you set cors to an array of domains that you would like to accept requests from. Setting cors to *
is generally not recommended, you should instead add the domains to the cors array like so:
cors: ['http://localhost:3000']
I try to write like cors: ['http://localhost:3000']
before in payload.config.ts,but it`s not work. "*"just for test
Normally, you set cors to an array of domains that you would like to accept requests from. Setting cors to
*
is generally not recommended, you should instead add the domains to the cors array like so:cors: ['http://localhost:3000']
http:// is not a part of domain, and cors: '*'
not working.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.