tangled
alpha
login
or
join now
openstatus.dev
/
openstatus
5
fork
atom
Openstatus
www.openstatus.dev
5
fork
atom
overview
issues
pulls
pipelines
trying redirect
thibault.tngl.sh
3 months ago
d8f90cc1
d5ad403d
+35
-1
1 changed file
expand all
collapse all
unified
split
apps
status-page
src
middleware.ts
+35
-1
apps/status-page/src/middleware.ts
···
17
17
const hostnames = host?.split(/[.:]/) ?? url.host.split(/[.:]/);
18
18
const pathnames = url.pathname.split("/");
19
19
20
20
-
console.log({ hostnames, pathnames, host, urlHost: url.host });
20
20
+
const subdomain = getValidSubdomain(url.host);
21
21
+
console.log({
22
22
+
hostnames,
23
23
+
pathnames,
24
24
+
host,
25
25
+
urlHost: url.host,
26
26
+
subdomain,
27
27
+
});
21
28
22
29
if (
23
30
hostnames.length > 2 &&
···
29
36
} else {
30
37
prefix = pathnames[1].toLowerCase();
31
38
type = "pathname";
39
39
+
}
40
40
+
41
41
+
if (subdomain !== null) {
42
42
+
prefix = subdomain.toLowerCase();
32
43
}
33
44
34
45
console.log({ pathname: url.pathname, type, prefix });
···
131
142
"/((?!api|assets|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
132
143
],
133
144
};
145
145
+
146
146
+
export const getValidSubdomain = (host?: string | null) => {
147
147
+
let subdomain: string | null = null;
148
148
+
if (!host && typeof window !== "undefined") {
149
149
+
// On client side, get the host from window
150
150
+
// biome-ignore lint: to fix later
151
151
+
host = window.location.host;
152
152
+
}
153
153
+
// we should improve here for custom vercel deploy page
154
154
+
if (host?.includes(".") && !host.includes(".vercel.app")) {
155
155
+
const candidate = host.split(".")[0];
156
156
+
if (candidate && !candidate.includes("www")) {
157
157
+
// Valid candidate
158
158
+
subdomain = candidate;
159
159
+
}
160
160
+
}
161
161
+
162
162
+
// In case the host is a custom domain
163
163
+
if (host && !(host?.includes("stpg.dev") || host?.endsWith(".vercel.app"))) {
164
164
+
subdomain = host;
165
165
+
}
166
166
+
return subdomain;
167
167
+
};