[Content]: Middleware examples use the pre-3.0 `(request, next)` shape; start mode now calls `(event, next)` and `next(request)` throws
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu với các ví dụ middleware trên những trang được liệt kê: building-apps/middleware-and-api-routes, guides/protected-routes, building-apps/sessions-and-auth, reference/vite-plugin-solid/start và reference/filesystem-routing/api. So sánh chữ ký của chúng với src/middleware.ts trong template solid-v2/fullstack và kiểu được báo cáo ở phiên bản 3.0.1. Cập nhật các ví dụ và hướng dẫn đã lỗi thời để khớp với API hiện tại; hoàn tất khi các ví dụ được liệt kê không còn dùng dạng request-first hoặc next(request).
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
📚 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 /.
- Ngôn ngữ chính
- MDX
- Star
- 291
- Fork
- 369
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 39
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của solidjs/solid-docs
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
solidjs/solid-docs#1713 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
solidjs/solid-docs#1635 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Content]: Cloudflare WorkersCó thể đã có người làm @Janani-bn đã nhận 52 ngày trước. Đang mởgood first issue solid solidstart
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
solidjs/solid-docs#1522 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Content]: v2 Store documentation is unclear on class instancesCó thể đã có người làm @LadyBluenotes đã nhận 14 ngày trước. Đang mởpending review
solidjs/solid-docs#1687 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Content]: Add a concrete DOM-binding example to fine-grained reactivityCó thể làm lại được @LadyBluenotes đã nhận 85 ngày trước và không có pull request nào đang mở. Đang mởpending review
solidjs/solid-docs#1637 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/solid-docs
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs discussion
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openfga/openfga.dev#1436 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[内容勘误] STL常用模式章节实战演练中代码有问题Đang mởdocumentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
Awesome-Embedded-Learning-Studio/Tutorial_AwesomeModernCPP#335 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100