Skip to content

feat(routing): add directory middleware - #1056

Merged
cpojer merged 17 commits into
mainfrom
feat/directory-middleware
Dec 6, 2026
Merged

cpojer merged 17 commits into
mainfrom
feat/directory-middleware

Conversation

@hyfdev

@hyfdev hyfdev commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

A _middleware.ts file under routes/ now guards every HTTP and WebSocket route in its directory and below, as suggested in #808.

// routes/admin/_middleware.ts
import { defineMiddleware } from 'void';
import { getUser } from 'void/auth';

export default defineMiddleware(async (c, next) => {
  if (!getUser()) return c.text('Unauthorized', 401);
  await next();
});

Today the same guard has to be added to every handler under routes/admin/, or written as global middleware that checks the path.

Void runs these guards after global middleware, from routes/ down to the directory of the file that answers the request, before that file's handler runs.

Guards see the route params, and their responses behave the same as in global middleware.

An existing _middleware.* file under routes/ now runs as a guard, so a helper with that name needs a new one.

Pages are unchanged.

Builds on #1055.

Part of #808.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Cloudflare builds and deploys previews for this pull request. Learn more about Cloudflare previews.

Worker Status Deployment Commit
void-cloud Deployed Preview 6afc10f

Updated: Dec 6, 2026, 12:57 UTC | Dashboard

@hyfdev
hyfdev changed the base branch from main to fix/pages-middleware-diagnostic December 6, 2026 06:01
@hyfdev
hyfdev added this pull request to stack #1062 December 6, 2026 06:01
@cpojer
cpojer marked this pull request as ready for review December 6, 2026 12:39

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for sending a PR!

Base automatically changed from fix/pages-middleware-diagnostic to main December 6, 2026 12:55
Copilot AI balanced review requested due to automatic review settings December 6, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@cpojer
cpojer merged commit fd74b7e into main Dec 6, 2026
21 checks passed
@cpojer
cpojer deleted the feat/directory-middleware branch December 6, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants