H
Hono•2mo ago
Dmitry

Issue with c.req.formData() on Vercel

Hi I have a Hono API deployed on Vercel. I have a function that starts like this
// Pusher auth route
const pusherAuth = factory.createHandlers(authMiddleware, async (c) => {
// Get socket_id and channel_name from the request
const formData = await c.req.formData()
const socketId = formData.get('socket_id')?.toString()
const channelName = formData.get('channel_name')?.toString()

if (!socketId || !channelName) {
return c.json({ message: 'Invalid params' }, 400)
}

const user = c.get('user')

// ... (More code below)
// Pusher auth route
const pusherAuth = factory.createHandlers(authMiddleware, async (c) => {
// Get socket_id and channel_name from the request
const formData = await c.req.formData()
const socketId = formData.get('socket_id')?.toString()
const channelName = formData.get('channel_name')?.toString()

if (!socketId || !channelName) {
return c.json({ message: 'Invalid params' }, 400)
}

const user = c.get('user')

// ... (More code below)
For some reason when I send a request to this endpoint's function... it just hangs and times out on the const formData = await c.req.formData() line. This line works just fine locally.. but when I deploy to Vercel.. it just hangs and eventually times out. Anyone know what the issue could be?
No description
15 Replies
Dmitry
DmitryOP•2mo ago
Did this just to debug (see screenshot).. and the endpoint no longer times out.. something is up with the await c.req.formData() function
ambergristle
ambergristle•2mo ago
so the authMiddleware gets executed?
Dmitry
DmitryOP•2mo ago
Yes
ambergristle
ambergristle•2mo ago
and i assume that you've used logs to verify that the request is hanging at await c.req.formData(), not before or after are you using app or page router? (i assume this is a backend for a next app) also, can you share the implementation of authMiddleware?
Dmitry
DmitryOP•2mo ago
Yes i've done something like this
No description
Dmitry
DmitryOP•2mo ago
I can see "1" being printed in my Vercel logs I'm not using Next.js.. i'm just deploying a regular Hono app to Vercel The issue I don't believe is with AuthMiddleware.. it works fine and other routes have no issue with it.
ambergristle
ambergristle•2mo ago
i get that. but maybe its doing something that would interfere with c.req.formData what's motivating your choice of vercel? this is just a shot in the dark. doesn't really seem related, but could be worth a try: https://github.com/honojs/hono/issues/1256#issuecomment-1703549234 oooh. this seems like it might be the same as your issue though: https://github.com/vercel/next.js/issues/64002
Dmitry
DmitryOP•2mo ago
Hey @ambergristle I think I actually figured it out.. I believe it was Vercel's "Bot Protection" actually blocking the request. I disabled Bot Protection and now it works 😛
ambergristle
ambergristle•2mo ago
glad you got it sorted!
Dmitry
DmitryOP•2mo ago
I appreciate your time and assistance! Also I like Vercel for it's reliability for the most part! Don't like having to fuss around with servers, etc 🙂 I know it's more expensive.. but.... idk 😄
ambergristle
ambergristle•2mo ago
have you had issues with other serverless providers?
Dmitry
DmitryOP•2mo ago
I do like Cloudflare's Workers platform.. but the only thing that stopped me from using them was the worker size limit (10MB I believe?) I just didn't want to hit that limit as I scaled up my application There was also the issue previously around NodeJS compatibility.. but i'm pretty sure it's much better now
ambergristle
ambergristle•2mo ago
gotcha. what about fly.io, digitalocean, koyeb, etc.?
Dmitry
DmitryOP•2mo ago
Fly.io has had terrible reliability in the past when I tried them. Was stuck not being able to deploy updates for like 8 hours one day 💀 DigitalOcean/Hetzner are decent.. but again just don't really want to manage infra. The best platform i've prob seen is Railway.. really nice what they're building over there!
ambergristle
ambergristle•2mo ago
i see. that scans thanks for sharing your perspective + experiences!

Did you find this page helpful?