Skip to content

Commit e5dbd54

Browse files
committed
Add framework-free nitro preview repro for the aws-lambda 404
Standalone nitro + Vite build with a single route. Reproduces the preview 404 stub with preset: 'aws-lambda' (srvx loadServerEntry has no branch for the handler-only export); returns 200 when swapped to preset: 'node-server'. Targeted by nitrojs/nitro#4052.
1 parent 8599a37 commit e5dbd54

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

nitro-only/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# nitro-only preview 404 repro
2+
3+
Framework-free reproduction of the nitro preview bug that surfaces in TanStack Start + prerender.
4+
Nitro + Vite, no framework plugins, no other wrappers.
5+
6+
## Bug
7+
8+
With `preset: "aws-lambda"`, `nitro preview` returns **HTTP 404** on every route. With `preset: "node-server"` (swap the line in `nitro.config.ts`), the same routes return **200 OK**.
9+
10+
Root cause: aws-lambda's runtime exports only `{ handler }`. srvx's `loadServerEntry` fetch-extraction cascade (`src/loader.ts:163-178`) has no branch that matches `{ handler }`, so `entry.fetch` returns `undefined`. `nitro/src/preview.ts:74-75` keeps its default `() => new Response("Not Found", { status: 404 })` stub, and serves it for every request.
11+
12+
## Reproduce
13+
14+
```bash
15+
cd nitro-only
16+
npm install
17+
npx nitro build
18+
npx nitro preview &
19+
sleep 1
20+
curl -i http://localhost:3000/hello
21+
# HTTP/1.1 404
22+
# content-type: text/plain;charset=UTF-8
23+
# Not Found
24+
25+
kill %1
26+
```
27+
28+
Change `preset: "aws-lambda"` to `preset: "node-server"` in `nitro.config.ts`, rebuild, and the same curl returns `200 OK` with body `hello`.
29+
30+
## Versions
31+
32+
Pinned in `package.json` at the nitro beta where the bug was first investigated; also reproduces on `nitro@nightly` at audit time.
33+
34+
## Fix in flight
35+
36+
[nitrojs/nitro#4052](https://github.com/nitrojs/nitro/pull/4052) adds `export default { fetch: nitroApp.fetch }` to the aws-lambda runtime, which triggers srvx's `mod.default.fetch` branch.

nitro-only/nitro.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from "nitro";
2+
3+
export default defineConfig({
4+
preset: "aws-lambda",
5+
serverDir: ".",
6+
});

nitro-only/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "nitro-only-repro",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "nitro build",
7+
"preview": "nitro preview"
8+
},
9+
"dependencies": {
10+
"nitro": "3.0.260311-beta"
11+
}
12+
}

nitro-only/routes/hello.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineHandler } from "nitro";
2+
3+
export default defineHandler(() => "hello");

0 commit comments

Comments
 (0)