Skip to content

feat(routing): add directory middleware - #1056

Draft
hyfdev wants to merge 10 commits into
mainfrom
feat/directory-middleware
Draft

hyfdev wants to merge 10 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 9322183

Updated: Dec 6, 2026, 03:25 UTC | Dashboard

This branch has not been deployed

No deployments
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.

1 participant