cli icon indicating copy to clipboard operation
cli copied to clipboard

Dynamic route handler fails occasionally on Windows with 404

Open Everspace opened this issue 2 years ago • 6 comments
trafficstars

Environment

Nuxt project info:


  • Operating System: Windows_NT
  • Node Version: v18.13.0
  • Nuxt Version: 3.7.0
  • CLI Version: 3.7.3
  • Nitro Version: 2.6.2
  • Package Manager: [email protected]
  • Builder: -
  • User Config: modules, runtimeConfig
  • Runtime Modules: @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

The following sandbox will produce the problem when the wayfinderContentDir in nuxt.config.ts is set to ./data rather than ./data_mini on a Windows machine

https://codesandbox.io/p/sandbox/naughty-platform-hrsvqk

This will sporadically require moving between the pages of / and /craft/[id].vue, where you can see the particular item with only the requested ID rather than it's name and description displayed.

Describe the bug

Occasionally instead of receiving an output, instead a dynamic route handler throws a 404 when under enough stress(?) on windows platforms.

Additional context

This problem seems to be when I have a large enough file loaded in the context of a route handler. The items.json provided when stripped of the localization information drops from ~250kb, to ~45kb, and reduces or eliminates the problem.

In addition the problem does not seem to be reproducible on WSL, or in the code sandbox.

Logs

XHRGET
http://localhost:3000/api/item/Spectra_Ruins_C_GW3
[HTTP/1.1 404 Cannot find any path matching /api/item/Spectra_Ruins_C_GW3. 5ms]

	
statusCode	404
statusMessage	"Cannot find any path matching /api/item/Spectra_Ruins_C_GW3."
stack	[]

Everspace avatar Aug 31 '23 18:08 Everspace

+1

i use catch all routes for server api on my nuxt app image

it works well on nuxt v3.6.5 but after update (3.6.5 -> 3.7.0) sometimes api response randomly returns 404 errors image

and actually it didn't hit my server logs. most weired thing is it happens only on dev server



qoo1476 avatar Sep 01 '23 00:09 qoo1476

Would you see if this is possible to reproduce using just nitro? It seems like this might be a nitro issue.

danielroe avatar Sep 01 '23 08:09 danielroe

Porting the example repo to a simple nitro with minimum changes, I pointed my nuxt app to source from it. I occasionally also see this 404 when going useFetch("http://localhost:3001/api/item/" + itemId) on windows, but not while I'm in WSL.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3002/api/item/LootGoblinResource. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 404.

The config for nitro is:

const fat = true

export default defineNitroConfig({
  runtimeConfig: {
    wayfinderContentDir: fat ? "./data" : "./data_minified",
  },
  routeRules: {
    '/api/**': {
      cors: true,
      headers: {
        'Access-Control-Allow-Origin': "*"
      }
    }
  }
});

In testing I've found that the smaller json makes it less frequent, but still results in the 404 upstream.

Everspace avatar Sep 02 '23 18:09 Everspace

I should mention I am only running via pnpm run dev for this. I have not tried it with the deploy'd version.

Everspace avatar Sep 02 '23 18:09 Everspace

cc: @pi0

danielroe avatar Sep 04 '23 10:09 danielroe

I meet the same problem when i sliced a file into chunks and upload with Promise.all. I think the problem was caused by multiple post requests in the same time. When i use await instead of Promise.all, it works well. But i can not use await because of the efficiency. By the way, the problem does not happen in production when use npm run build && npm run preview.

1714080902120 avatar Sep 07 '23 05:09 1714080902120