Home / File/ middleware.ts — astro Source File

middleware.ts — astro Source File

Architecture documentation for middleware.ts, a typescript file in the astro codebase. 1 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  f1a22e21_81a4_0c7a_8da2_bb44ad968cac["middleware.ts"]
  3a7a7ff7_6c64_95f9_af85_4deb518834f1["astro:middleware"]
  f1a22e21_81a4_0c7a_8da2_bb44ad968cac --> 3a7a7ff7_6c64_95f9_af85_4deb518834f1
  style f1a22e21_81a4_0c7a_8da2_bb44ad968cac fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { defineMiddleware } from 'astro:middleware'

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()
})

Subdomains

Functions

Dependencies

  • astro:middleware

Frequently Asked Questions

What does middleware.ts do?
middleware.ts is a source file in the astro codebase, written in typescript. It belongs to the ContentCollections domain, SchemaValidation subdomain.
What functions are defined in middleware.ts?
middleware.ts defines 1 function(s): onRequest.
What does middleware.ts depend on?
middleware.ts imports 1 module(s): astro:middleware.
Where is middleware.ts in the architecture?
middleware.ts is located at packages/astro/e2e/fixtures/cloudflare/src/middleware.ts (domain: ContentCollections, subdomain: SchemaValidation, directory: packages/astro/e2e/fixtures/cloudflare/src).

Analyze Your Own Codebase

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

Try Supermodel Free