#Vercel Cors error

38 messages · Page 1 of 1 (latest)

true sparrow
#

this cors error only started happening after i deployed my projects on vercel, because they worked fine in production and ive tried a lot of stuff to fix this error such as configuring my vercel.json file, and configuring cors and i also tried adding a proxy and even that didnt work, it still gives me the same error, you can check some of the codes below

// (vercel.json)
"headers":
{ "Access-Control-Allow-Origin": "https://valton-frontend.vercel.app",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Methods": "GET,OPTIONS,PATCH,DELETE,POST,PUT",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
}

// (index.js)
app.use(cors({
origin: 'https://valton-frontend.vercel.app',
allowedHeaders: ['Content-Type', 'Authorization'],
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
credentials: true,
}))

app.options('*', (req, res) => {
res.header('Access-Control-Allow-Origin', 'https://valton-frontend.vercel.app');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.sendStatus(204); // No Content
});

warm copperBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

dire dew
hot vigilBOT
# true sparrow
Please add more information to your question

Your question currently does not have sufficient information for people to be able to help. Please add more information to help us help you, for example: relevant code snippets, a reproduction repository, and/or more detailed error messages. See more info on how to ask a good question in https://discord.com/channels/752553802359505017/1138338531983491154 and #welcome message.

true sparrow
#

i sent the errors, and i sent the cors codes, and i specified that the error comes from vercel because it works fine in production @dire dew

#

what else do i need to send

dire dew
# true sparrow what else do i need to send

please provide the actual request (with all information) from the network tab and the full result incl. status code
I can see the route and the status inside your screenshot.

I don't see the actual request, nor the information's that are sent with it like headers. I also don't see the full result.

true sparrow
dire dew
true sparrow
#

i dont see the actual request in my networks tab

dire dew
dire dew
dire dew
#

Thanks for sharing the details. Make sure you don't leak anything when sharing details.

The way how you index your app looks pretty uncommon for me. Where inside the nextjs docs did you found that pattern?
https://nextjs.org/docs

dire dew
# true sparrow so how do i fix the error

we are currently on it. The error is a 404 error. So whereever you sent the OPTIONs to was not found. So I currently trying to find out how you initialize everything and asked you this: #1324234916766158869 message <--- click
So please answer that message to get your issue resolved.

btw. when you reply faster, it will be solved faster ;)

true sparrow
true sparrow
#

you can ask me for any code ill send it

#

im also using prisma with mongodb maybe vercel doesn’t support them idk?

dire dew
true sparrow
#

at this point if nothing works ill try to find smth else where i can host it for free

#

but i tried render and its so bad bcuz the free version has really long cold starts which take like 5 minutes

dire dew
true sparrow
dire dew
#

I am not experienced with express so there may be something that you can do, but I guess I am not the correct person to solve this thread

true sparrow
#

damn aight i dont think anyone else is gonna come here

#

i think fly.io has a free version

#

ima try that

dire dew
true sparrow
#

yea ive looked everywhere for a solution, i think the only thing you can do is host it somewhere else

true sparrow
#

aight ill do it tomorrow, cuz ima work on the project first

true sparrow
#

i deployed with render and it works but render has another problem where it can’t send cookies on ios devices SO GUYS theres only one solution… basically just use a postgresql database and then it will work with vercel. 😀