Home / Function/ onRequest() — astro Function Reference

onRequest() — astro Function Reference

Architecture documentation for the onRequest() function in middleware.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  8eb81631_e7fd_a388_bb55_01c19672fd80["onRequest()"]
  346ee168_af6c_1d78_a15e_5b26eca2e120["middleware.ts"]
  8eb81631_e7fd_a388_bb55_01c19672fd80 -->|defined in| 346ee168_af6c_1d78_a15e_5b26eca2e120
  style 8eb81631_e7fd_a388_bb55_01c19672fd80 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/integrations/cloudflare/test/fixtures/vite-plugin/src/middleware.ts lines 3–19

export const onRequest = defineMiddleware(async (ctx, next) => {
	const url = new URL(ctx.request.url);
	
	if (url.pathname.includes("/mid/to-redirect")) {
		return ctx.redirect("/mid/from-redirect");
	}
	if (url.pathname.includes("/mid/to-rewrite")) {
		return ctx.rewrite("/mid/from-rewrite");
	}
	
	
	ctx.locals.getGreeting = () => {
			return `Hello from ${url.pathname}`;
	};
	
	return next()
})

Domain

Subdomains

Frequently Asked Questions

What does onRequest() do?
onRequest() is a function in the astro codebase, defined in packages/integrations/cloudflare/test/fixtures/vite-plugin/src/middleware.ts.
Where is onRequest() defined?
onRequest() is defined in packages/integrations/cloudflare/test/fixtures/vite-plugin/src/middleware.ts at line 3.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free