Let global middleware declare the paths it runs on
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- tooling
調査の方向性
Start by reading packages/void/src/asset-worker-bypass.ts and the middleware loading and execution flow; the issue does not name those entry points or any tests. Trace how patternCanReachUnder() is used for route, page, and auth patterns. Done means middleware matchers skip nonmatching requests and the asset bypass remains enabled when no middleware matcher can reach assets, while files without a matcher retain current behavior.
索引モデルが issue の本文から書いたものです。
説明
Version
void 1.8.0, and main at 004624f
Problem
Every file in middleware/ runs on every request, so a middleware that only matters for one section has to test the path itself:
// middleware/04.admin.ts
const ADMIN_PATH = /^\/admin(\/|$)/;
export default defineMiddleware(async (c, next) => {
if (!ADMIN_PATH.test(c.req.path)) return next();
// …
});
Void's own dashboard does the same in platform/packages/dashboard/middleware/01.auth.ts, with PUBLIC_PATHS and PUBLIC_PREFIXES.
That's only boilerplate, but having middleware at all also costs every static file its free request. resolveAssetWorkerBypass() in packages/void/src/asset-worker-bypass.ts gives up the bypass as soon as there's any middleware:
facts.hasMiddleware ||
So in a build with middleware, every hashed JS, CSS and image file starts the Worker, and each middleware runs for it. Any middleware that reads a session, KV or D1 has to skip asset paths by hand, or every asset waits on that read. Void can't tell which middleware might touch /assets/, so it has to assume all of them do.
Proposal
Let a middleware file export the paths it runs on, in the same glob syntax as run_worker_first:
// middleware/04.admin.ts
export const matcher = ['/admin', '/admin/**'];
export default defineMiddleware(async (c, next) => {
// runs only for /admin and below
});
- A file without
matcherruns on every request, as today, so existing apps see no change. !patterns exclude paths, as inrun_worker_first, so a middleware that sets shared data for every page can still leave assets out with['/**', '!/assets/**'].- Files still run in filename order; one that doesn't match is skipped.
hasMiddlewarebecomes "has middleware that can reach the assets folder": if every file has amatcherand none of them can reach it, checked withpatternCanReachUnder()as the bypass already does for route, page and auth patterns, the bypass stays on.
Matching on the request path alone keeps it decidable at build time. A function form, like matcher: (c) => …, couldn't be checked against the assets folder, so it would have to keep the Worker in front.
Prior art
- Next.js:
export const config = { matcher: [...] }inmiddleware.ts, with path patterns and negative lookaheads, so_next/staticcan be left out. - TanStack Start: middleware attached to a route runs only for that route and below.
- TanStack Router:
beforeLoadon a layout route runs for its children only.
- 主要言語
- TypeScript
- スター
- 684
- フォーク
- 83
- 平均マージ
- 15時間 22分
- マージ済み PR(30日)
- 219
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
voidzero-dev/void のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
voidzero-dev/void#835 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
voidzero-dev/void#834 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
voidzero-dev/void#833 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 32/100
voidzero-dev/void#832 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
voidzero-dev/void#825 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
voidzero-dev/void の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
open-webui/tether#52 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
AykutSarac/jsoncrack.com#616 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
melgarafael/DeskcommCRM#4679 ·
メンテナーはふだん 1 日以内に返信
-
enhancement size:medium
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信