Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting random 404s #628

Closed
juliusmarminge opened this issue Jan 23, 2024 · 1 comment
Closed

getting random 404s #628

juliusmarminge opened this issue Jan 23, 2024 · 1 comment

Comments

@juliusmarminge
Copy link

juliusmarminge commented Jan 23, 2024

Environment

  • Node.js 20.11
  • h3 1.10.0
  • listhen 1.5.6

Reproduction

https://github.com/pingdotgg/uploadthing/tree/h3-debug
https://github.com/pingdotgg/uploadthing/blob/h3-debug/examples/backend-adapters/server/src/h3.ts

Describe the bug

I have noticed a random 404 error when fetching from itself, i.e. /api/uploadthing fetches /api/uploadthing on the same server. We use this for our dev webhook but it seems to fails for some reason...

To reproduce, checkout the repo and the linked branch, pnpm i, pnpm build, cd examples/backend-adapters and run the h3 example using pnpm dev:h3. This starts a vite server up at port 5173 as well as a listhen instance on port 3000 with the h3 app.

Attempt to upload an image, and wait for the 404 to show up.

I also added a simple nitro server that you can compare to (run using pnpm dev:nitro), which works out of the box without issues. Maybe I have configured the h3 app wrong?

Additional context

I also tried using a "raw" node.js server to eliminate listhen as the possible cause of error but that had the same behavior

Running the h3 app

CleanShot.2024-01-23.at.17.02.38.mp4

Running Nitro for comparison

CleanShot.2024-01-23.at.17.04.23.mp4

Logs

No response

@pi0
Copy link
Member

pi0 commented Jan 25, 2024

Hi, dear @juliusmarminge. First, THANK YOU for spending time to make proper reproduction and write description and nice work in uploadthing library ❤️

I have did little investigation to find a simple fix! ~> pingdotgg/uploadthing#573

Some more context:

H3 router by default is in non-preemptive mode (see #194 and #183 -- it is to allow multiple routers) but in Nitro, the router is preemptive because we can safely assume it for top-level router (unjs/nitro#1504). When router is in non-preemptive mode and an event handler returns an undefined value (the issue in uploadthing), h3 keep search other middleware (which non of them also response) and finally give a 404 back.

Also I think if you like, we might introduce an UnStorage provider for upload thing! I think it would make usage much more ergonomic for Nitro/Nuxt users! ~> unjs/unstorage#389

Best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants