UNPKG

next-middleware-enhancer

Version:
2 lines (1 loc) 500 B
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("next/server");function i(r){return{middleware:async e=>{for(const{matcher:n,handler:t}of r)if(l(e.nextUrl.pathname,n)){const o=Array.isArray(t)?t:[t];for(const c of o){const a=await c(e);if(a)return a}}return s.NextResponse.next()},config:{matcher:r.map(({matcher:e})=>e)}}}function l(r,e){return new RegExp(`^${e.replace(/:\w+\*/g,".*").replace(/:\w+/g,"[^/]+")}$`).test(r)}exports.createMiddleware=i;