Open PodTT opened 1 year ago
@yusukebe Trying this out as well. The app.get
example provided is working. However, I get a server 500 error with any different method that I'm trying, i.e. app.post()
I'm seeing this as well when using c.req.formData()
or c.req.parseBody()
(which uses the formData
method under the hood).
I suspect it may be related to this: https://github.com/orgs/vercel/discussions/1426
Update, it turns out you need to add NODEJS_HELPERS=0
to your environment variables, then Hono will work in Vercel serverless (AWS Lambda)
I'm still having trouble. I'll get a 500 response on any post
method when adding a JSON payload (locally). It would be nice to see a complete working example somewhere
I couldn't get any of the examples in the docs working in vercel. Only locally. Guessing they haven't been updated.
hi folks, we are interested in this as well. is this bug going to be fixed ?
also - we deploy using vercel deploy --prebuilt
for all our code (which means we build to vercel build output locally). I'm migrating from hattip which builds and outputs Build Output compatible .vercel
directories. Not sure if that is something Hono supports
I would like to investigate but I am busy cleaning up other Issues, I think it may be a Vercel issue but I am not sure. I will investigate when I get some time.
I'm still having trouble. I'll get a 500 response on any
post
method when adding a JSON payload (locally). It would be nice to see a complete working example somewhere
This is an Hono server deployed to Vercel: https://github.com/hwy-js/hwy/tree/0f9d7f662984267e24e15a22c960425bcbdb92e2/docs
This does not use the Vercel CLI, so maybe that's where the issues are cropping up for others. Anyway, maybe this example can help someone. There aren't POSTs in this example, but works fine if you add them (both locally and when deployed).
The tricks are:
NODEJS_HELPERS=0
in your Vercel production environment variables. POST requests break if you don't do this!api
folder, e.g., ~/api/main.js
.vercel.json
to point to your server entry file.Hi , Could you elaborate on your deployment please - do u use "vercel build && vercel deploy --prebuilt" for the deployment. I checked the package.json, but couldn't figure how the deployment to vercel was happening.
Also could u clarify the role of api/main js for a full blown hono application? Would that file just contain the router? I'm just trying to figure out a realistic application with many endpoints, etc.
On Thu, Sep 28, 2023, 04:06 Sam Cook @.***> wrote:
I'm still having trouble. I'll get a 500 response on any post method when adding a JSON payload (locally). It would be nice to see a complete working example somewhere
This is an Hono server deployed to Vercel: https://github.com/hwy-js/hwy/tree/0f9d7f662984267e24e15a22c960425bcbdb92e2/docs
This does not use the Vercel CLI, so maybe that's where the issues are cropping up for others. Anyway, maybe this example can help someone. There aren't POSTs in this example, but works fine if you add them (both locally and when deployed).
The tricks are:
- Set NODEJS_HELPERS=0 in your Vercel production environment variables. POST requests break if you don't do this!
- Your function needs to be in an API folder, e.g., ~/API/main.js.
- Adjust vercel.json to point to your server entry file.
— Reply to this email directly, view it on GitHub https://github.com/honojs/hono/issues/1256#issuecomment-1738197919, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAASYUZNTM6C2DMSYCDVFETX4SS7VANCNFSM6AAAAAA2UCI5PE . You are receiving this because you commented.Message ID: @.***>
@PodTT @sandys and @yusukebe I found a way to get this to work. I had the same problem as you @PodTT – I wanted to run hono api as serveless nodejs function, not on edge. Why? Because I want to use drizzle + postgres … which don't run on edge. I found there are 4 steps:
NODEJS_HELPERS=0
to the .env file (and env variables on Vercel)"type": "module"
to the package.jsonexport const config…
from index.ts`Some further explanation (my understanding)
Github repo with example https://github.com/pkorac/serverlesshono
Hope this helps
@PodTT @sandys and @yusukebe I found a way to get this to work. I had the same problem as you @PodTT – I wanted to run hono api as serveless nodejs function, not on edge. Why? Because I want to use drizzle + postgres … which don't run on edge. I found there are 4 steps:
- Install hono using the default instaler and use vercel template
- Add the
NODEJS_HELPERS=0
to the .env file (and env variables on Vercel)- Add
"type": "module"
to the package.json- Remo the
export const config…
from index.ts`Some further explanation (my understanding)
- NODEJS helpers I believe let hono do hono instead of vercel's request helpers, etc.
- Package.json type:module let's you use import something from "something" syntax instead of require()
- export const config tells vercel to run stuff on edge… which you don't want
Github repo with example https://github.com/pkorac/serverlesshono
Hope this helps
This seems to be the most common and stable fix, I believe we should close this thread with this answer.
Is there any official way of deploying a hono app to Vercel serverless functions? I am not talking about edge. I am using prisma with Hono and it would be nice to deploy to serverless functions. As far as I know Prisma is not supported on edge runtimes, it seems like Vercel serverless functions are my only option. I could not find documentation on the website relating to this topic.