<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Middleware on Commentary of Takao</title><link>https://takao.blog/en/tags/middleware/</link><description>Recent content in Middleware on Commentary of Takao</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Commentary of Takao</copyright><lastBuildDate>Sat, 13 Jun 2026 23:11:50 +0900</lastBuildDate><atom:link href="https://takao.blog/en/tags/middleware/index.xml" rel="self" type="application/rss+xml"/><item><title>Next.js Middleware: Routing, Auth, and Edge Computing</title><link>https://takao.blog/en/web/nextjs-middleware/</link><pubDate>Tue, 18 Jun 2024 00:00:00 +0900</pubDate><guid>https://takao.blog/en/web/nextjs-middleware/</guid><description>&lt;img src="https://takao.blog/img/thumnail.webp" alt="Featured image of post Next.js Middleware: Routing, Auth, and Edge Computing" /&gt;&lt;h2 id="introduction"&gt;Introduction
&lt;/h2&gt;&lt;p&gt;Next.js Middleware executes before every request, running at the Edge or serverless region. A single &lt;code&gt;middleware.ts&lt;/code&gt; file at the project root intercepts incoming requests and can redirect, rewrite, manipulate headers, or perform authentication checks before the request reaches the matched route.&lt;/p&gt;
&lt;p&gt;Middleware is ideal for fast, edge-based decisions that should happen before page rendering. It does not run on static assets or &lt;code&gt;_next/static&lt;/code&gt; by default.&lt;/p&gt;
&lt;h2 id="basic-structure"&gt;Basic Structure
&lt;/h2&gt;&lt;p&gt;The middleware file exports a function that receives &lt;code&gt;NextRequest&lt;/code&gt; and returns &lt;code&gt;NextResponse&lt;/code&gt;, along with a &lt;code&gt;config&lt;/code&gt; object that defines which paths trigger execution.&lt;/p&gt;</description></item></channel></rss>