Polyfill URLPattern (#398)

This commit is contained in:
Giancarlo Buomprisco
2025-10-22 14:53:37 +09:00
committed by GitHub
parent f6d573819b
commit bc9ab21b5d
4 changed files with 21 additions and 6 deletions

View File

@@ -70,6 +70,7 @@
"react-i18next": "^16.1.4", "react-i18next": "^16.1.4",
"recharts": "2.15.3", "recharts": "2.15.3",
"tailwind-merge": "^3.3.1", "tailwind-merge": "^3.3.1",
"urlpattern-polyfill": "^10.1.0",
"zod": "^3.25.74" "zod": "^3.25.74"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -2,7 +2,6 @@ import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { CsrfError, createCsrfProtect } from '@edge-csrf/nextjs'; import { CsrfError, createCsrfProtect } from '@edge-csrf/nextjs';
import { URLPattern } from 'node:url';
import { isSuperAdmin } from '@kit/admin'; import { isSuperAdmin } from '@kit/admin';
import { checkRequiresMultiFactorAuthentication } from '@kit/supabase/check-requires-mfa'; import { checkRequiresMultiFactorAuthentication } from '@kit/supabase/check-requires-mfa';
@@ -36,7 +35,7 @@ export async function proxy(request: NextRequest) {
const csrfResponse = await withCsrfMiddleware(request, response); const csrfResponse = await withCsrfMiddleware(request, response);
// handle patterns for specific routes // handle patterns for specific routes
const handlePattern = matchUrlPattern(request.url); const handlePattern = await matchUrlPattern(request.url);
// if a pattern handler exists, call it // if a pattern handler exists, call it
if (handlePattern) { if (handlePattern) {
@@ -130,7 +129,14 @@ async function adminMiddleware(request: NextRequest, response: NextResponse) {
/** /**
* Define URL patterns and their corresponding handlers. * Define URL patterns and their corresponding handlers.
*/ */
function getPatterns() { async function getPatterns() {
let URLPattern = globalThis.URLPattern;
if (!URLPattern) {
const { URLPattern: polyfill } = await import('urlpattern-polyfill');
URLPattern = polyfill as typeof URLPattern;
}
return [ return [
{ {
pattern: new URLPattern({ pathname: '/admin/*?' }), pattern: new URLPattern({ pathname: '/admin/*?' }),
@@ -195,8 +201,8 @@ function getPatterns() {
* Match URL patterns to specific handlers. * Match URL patterns to specific handlers.
* @param url * @param url
*/ */
function matchUrlPattern(url: string) { async function matchUrlPattern(url: string) {
const patterns = getPatterns(); const patterns = await getPatterns();
const input = url.split('?')[0]; const input = url.split('?')[0];
for (const pattern of patterns) { for (const pattern of patterns) {

View File

@@ -1,6 +1,6 @@
{ {
"name": "next-supabase-saas-kit-turbo", "name": "next-supabase-saas-kit-turbo",
"version": "2.19.1", "version": "2.19.2",
"private": true, "private": true,
"sideEffects": false, "sideEffects": false,
"engines": { "engines": {

8
pnpm-lock.yaml generated
View File

@@ -276,6 +276,9 @@ importers:
tailwind-merge: tailwind-merge:
specifier: ^3.3.1 specifier: ^3.3.1
version: 3.3.1 version: 3.3.1
urlpattern-polyfill:
specifier: ^10.1.0
version: 10.1.0
zod: zod:
specifier: ^3.25.74 specifier: ^3.25.74
version: 3.25.76 version: 3.25.76
@@ -8529,6 +8532,9 @@ packages:
uri-js@4.4.1: uri-js@4.4.1:
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
urlpattern-polyfill@10.1.0:
resolution: {integrity: sha512-IGjKp/o0NL3Bso1PymYURCJxMPNAf/ILOpendP9f5B6e1rTJgdgiOvgfoT8VxCAdY+Wisb9uhGaJJf3yZ2V9nw==}
urql@4.2.2: urql@4.2.2:
resolution: {integrity: sha512-3GgqNa6iF7bC4hY/ImJKN4REQILcSU9VKcKL8gfELZM8mM5BnLH1BsCc8kBdnVGD1LIFOs4W3O2idNHhON1r0w==} resolution: {integrity: sha512-3GgqNa6iF7bC4hY/ImJKN4REQILcSU9VKcKL8gfELZM8mM5BnLH1BsCc8kBdnVGD1LIFOs4W3O2idNHhON1r0w==}
peerDependencies: peerDependencies:
@@ -17491,6 +17497,8 @@ snapshots:
dependencies: dependencies:
punycode: 2.3.1 punycode: 2.3.1
urlpattern-polyfill@10.1.0: {}
urql@4.2.2(@urql/core@5.2.0(graphql@16.11.0))(react@19.2.0): urql@4.2.2(@urql/core@5.2.0(graphql@16.11.0))(react@19.2.0):
dependencies: dependencies:
'@urql/core': 5.2.0(graphql@16.11.0) '@urql/core': 5.2.0(graphql@16.11.0)