[Content]: Middleware examples use the pre-3.0 `(request, next)` shape; start mode now calls `(event, next)` and `next(request)` throws

Offen Anfängerfreundlich
#1,716 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
82/100
Issue-Typ
Dokumentation
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
typescript
Bereich
documentation

Rechercherichtung

Beginne mit den Middleware-Beispielen auf den aufgeführten Seiten: building-apps/middleware-and-api-routes, guides/protected-routes, building-apps/sessions-and-auth, reference/vite-plugin-solid/start und reference/filesystem-routing/api. Vergleiche ihre Signaturen mit solid-v2/fullstack-Vorlage src/middleware.ts und dem gemeldeten Typ für 3.0.1. Aktualisiere veraltete Beispiele und Anleitungen, damit sie der aktuellen API entsprechen; fertig ist die Arbeit, wenn die aufgeführten Beispiele nicht mehr die request-first-Form oder next(request) verwenden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

📚 Subject area/topic

Building apps (Middleware and API routes), Guides, Reference (@solidjs/vite-plugin, filesystem-routing)

📋 Page(s) affected (or suggested, for new content)

Examples break when copied:

Works at runtime, but the type annotation is the old shape:

Signature from an older release:

📋 Description of content that is out-of-date or incorrect

Since @solidjs/vite-plugin 3.0.0-next.48 (CHANGELOG 1702a19, marked BREAKING), start-mode middleware is event-first:

// @solidjs/vite-plugin 3.0.1, dist/types/src/request-event.d.ts
export type StartMiddleware = (
	event: StartRequestEvent,
	next: () => Promise<Response>
) => Response | Promise<Response>;

The request is event.request, and next() takes no arguments. To substitute the request, assign event.request before calling next(). The solid-v2/fullstack template's src/middleware.ts uses this shape (satisfies StartMiddleware[]).

The pages above still document the request-first shape, (request: Request, next: (request?: Request) => …), and say to call next(request). Copying them breaks the app.

Checked in dev with solid-js / @solidjs/web 2.0.3, @solidjs/vite-plugin 3.0.1, vite 8.3.8. I wrote a middleware exactly to the documented type and registered it with start.middleware:

export default async (request: Request, next: (request?: Request) => Response | Promise<Response>) => {
	console.log("[mw] request.url =", (request as any).url);
	return next(request);
};

The first argument is the event (request.url logs undefined), and every page answers 500 with:

[@solidjs/vite-plugin] start.middleware: next() takes no arguments. Middleware receives the request event — (event, next) — so to substitute the request, assign event.request = newRequest before calling next().

The guide's requireHttps and the protected-routes requireAccountSession would also fail at new URL(request.url) before they reach next().

Proposed fix: switch these examples to (event, next) with event.request, type the middleware module as StartMiddleware[] like the template does, and replace the next(request) paragraph with "assign event.request before calling next()". I'm happy to send a PR, one page or all of them, whichever you prefer.

🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)

Local steps: pnpm create solid@latest -t basic --solid --ts --ssr (rename the generated start: { node: true } to nodeServer: true), add middleware: './src/middleware.ts' to start, put the middleware above in src/middleware.ts, run pnpm dev, and open /.

Vorherrschende Sprache
MDX
Sterne
291
Forks
369
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
39

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus solidjs/solid-docs

Alle Issues in solidjs/solid-docs

Ähnliche Issues

Weitere Issues zu Documentation

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.