[Content]: Middleware examples use the pre-3.0 `(request, next)` shape; start mode now calls `(event, next)` and `next(request)` throws
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 82/100
- Issue 類型
- 文件
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
研究方向
從所列頁面中的 middleware 範例開始:building-apps/middleware-and-api-routes、guides/protected-routes、building-apps/sessions-and-auth、reference/vite-plugin-solid/start 和 reference/filesystem-routing/api。將它們的簽章與 solid-v2/fullstack 範本中的 src/middleware.ts 以及回報的 3.0.1 型別進行比較。更新過時的範例和指引,使其符合目前的 API;完成標準是所列範例不再使用 request-first 形式或 next(request)。
由索引模型根據 Issue 內容生成。
描述
📚 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:
- https://docs.solidjs.com/building-apps/middleware-and-api-routes ("Add a middleware": the
Middlewaretype,requireHttps,securityHeaders, and "Pass aRequesttonext(request)to replace the request") - https://docs.solidjs.com/guides/protected-routes ("Middleware for whole sections":
requireAccountSessionreadsrequest.url)
Works at runtime, but the type annotation is the old shape:
- https://docs.solidjs.com/building-apps/sessions-and-auth ("Authenticate once in middleware":
attachCustomer(_request: Request, next)) - https://docs.solidjs.com/reference/vite-plugin-solid/start (
### middleware: theMiddlewaretype)
Signature from an older release:
- https://docs.solidjs.com/reference/filesystem-routing/api (written from
v0.2.1; in 0.5.0createAPIHandlerreturns(input: Request | { request: Request }, next) => Promise<Response>)
📋 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 /.
- 主要語言
- MDX
- 星號
- 291
- 分支
- 369
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 39
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
solidjs/solid-docs 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
solidjs/solid-docs#1713 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
solidjs/solid-docs#1635 ·
維護者通常 1 天內回覆
-
[Content]: Cloudflare Workers可能已有人在做 @Janani-bn 於 52 天前認領。 未關閉good first issue solid solidstart
難度 2/5 1-3 小時 新手友好度 62/100
solidjs/solid-docs#1522 · 1 則留言 ·
維護者通常 1 天內回覆
-
[Content]: v2 Store documentation is unclear on class instances可能已有人在做 @LadyBluenotes 於 14 天前認領。 未關閉pending review
solidjs/solid-docs#1687 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[Content]: Add a concrete DOM-binding example to fine-grained reactivity可能重新可做 @LadyBluenotes 於 85 天前認領,目前沒有進行中的 PR。 未關閉pending review
solidjs/solid-docs#1637 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 solidjs/solid-docs 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
needs discussion
難度 2/5 1-3 小時 新手友好度 78/100
openfga/openfga.dev#1436 · 1 則留言 ·
維護者通常 2 天內回覆
-
documentation
難度 1/5 1 小時以內 新手友好度 86/100
Awesome-Embedded-Learning-Studio/Tutorial_AwesomeModernCPP#335 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 75/100
-
難度 1/5 1-3 小時 新手友好度 84/100