H
Hono5d ago
Eternal

[SOLVED] CORS with origin of "localhost" doesn't work

Code used:
app.use('*', cors({
origin: "localhost",
credentials: true
}))
app.use('*', cors({
origin: "localhost",
credentials: true
}))
Issue: the Allow Origin header isn't sent but the access-control-allow-credentials is set
2 Replies
ambergristle
ambergristle4d ago
what's the request Origin? if nothing else, i'd assume you need to include the protocol
Eternal
EternalOP3d ago
Origin is http://localhost:3000 Setting the origin in this code to http://localhost:3000 actually worked For future people that stumble across this post: set the origin paramter for cors on the backend to the exact base URL for the frontend. So literally just http://localhost:whatever port the frontend is on My frontend is using port 3000 So now I'm using
app.use('*', cors({
origin: "http://localhost:3000",
credentials: true
}))
app.use('*', cors({
origin: "http://localhost:3000",
credentials: true
}))
Thanks for your help, @ambergristle

Did you find this page helpful?