Skip to content

Commit cc8477e

Browse files
Copilotsyed-reza98
andcommitted
refactor: extract static file extensions to maintainable constant array
Improve code maintainability by extracting static file extensions to a constant array instead of using complex regex pattern Co-authored-by: syed-reza98 <71028588+syed-reza98@users.noreply.github.com>
1 parent b2332df commit cc8477e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

middleware.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ const PLATFORM_DOMAINS = [
7676
"vercel.app",
7777
];
7878

79+
/**
80+
* Static file extensions to skip in subdomain routing
81+
*/
82+
const STATIC_FILE_EXTENSIONS = [
83+
"js", "css", "png", "jpg", "jpeg", "gif", "svg", "ico",
84+
"woff", "woff2", "ttf", "eot", "webp", "avif",
85+
"json", "xml", "txt", "map", "webmanifest", "pdf",
86+
];
87+
7988
/**
8089
* Check if hostname is a potential custom domain (not a subdomain of platform)
8190
*/
@@ -126,9 +135,10 @@ function shouldSkipSubdomainRouting(
126135
// Skip Next.js internal routes
127136
if (pathname.startsWith("/_next")) return true;
128137

129-
// Skip static files (common file extensions; extend as needed)
138+
// Skip static files using maintainable extension list
130139
if (pathname.startsWith("/favicon")) return true;
131-
if (pathname.match(/\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot|webp|avif|json|xml|txt|map|webmanifest|pdf)$/i)) return true;
140+
const extension = pathname.split(".").pop()?.toLowerCase();
141+
if (extension && STATIC_FILE_EXTENSIONS.includes(extension)) return true;
132142

133143
// Skip checkout routes
134144
if (pathname.startsWith("/checkout")) return true;

0 commit comments

Comments
 (0)