tangled
alpha
login
or
join now
openstatus.dev
/
openstatus
5
fork
atom
Openstatus
www.openstatus.dev
5
fork
atom
overview
issues
pulls
pipelines
fix: config host value
Maximilian Kaske
6 months ago
0ac4c575
577b11ec
+21
-9
2 changed files
expand all
collapse all
unified
split
apps
web
next.config.js
src
middleware.ts
+8
-2
apps/web/next.config.js
···
85
85
source: "/_next/:path*",
86
86
has: [
87
87
{ type: "cookie", key: "sp_mode", value: "new" },
88
88
-
{ type: "host", value: "(?<slug>[^.]+)\\.(stpg\\.dev|localhost)" },
88
88
+
{
89
89
+
type: "host",
90
90
+
value: "(?<slug>[^.]+)\\.(openstatus\\.dev|localhost)",
91
91
+
},
89
92
],
90
93
destination: `http://${NEW_HOST}/_next/:path*`,
91
94
},
···
94
97
source: "/:path((?!_next/).*)",
95
98
has: [
96
99
{ type: "cookie", key: "sp_mode", value: "new" },
97
97
-
{ type: "host", value: "(?<slug>[^.]+)\\.(stpg\\.dev|localhost)" },
100
100
+
{
101
101
+
type: "host",
102
102
+
value: "(?<slug>[^.]+)\\.(openstatus\\.dev|localhost)",
103
103
+
},
98
104
],
99
105
// NOTE: we don't need the slug `/:slug/:path*` here because it will already be applied in the rewrites in the status-page app as subdomain
100
106
destination: `http://${NEW_HOST}/:path*`,
+13
-7
apps/web/src/middleware.ts
···
64
64
const pathname = req.nextUrl.pathname;
65
65
const subdomain = getValidSubdomain(host);
66
66
67
67
+
console.log({ subdomain });
68
68
+
67
69
// Subdomain handling: set mode cookie (legacy/new) and let next.config rewrites proxy
68
70
if (subdomain) {
69
71
const modeCookie = req.cookies.get("sp_mode")?.value; // "legacy" | "new"
70
72
const cached = modeCookie === "legacy" || modeCookie === "new";
71
73
let mode: "legacy" | "new" | undefined = cached ? modeCookie : undefined;
74
74
+
75
75
+
console.log({ mode, cached });
72
76
73
77
if (!mode) {
74
78
try {
···
81
85
}
82
86
}
83
87
88
88
+
console.log({ mode });
89
89
+
84
90
if (mode === "legacy") {
85
91
url.pathname = `/status-page/${subdomain}${url.pathname}`;
86
92
return NextResponse.rewrite(url);
···
104
110
}
105
111
106
112
const isPublicAppPath = publicAppPaths.some((path) =>
107
107
-
pathname.startsWith(path),
113
113
+
pathname.startsWith(path)
108
114
);
109
115
110
116
if (!req.auth && pathname.startsWith("/app/invite")) {
111
117
return NextResponse.redirect(
112
118
new URL(
113
119
`/app/login?redirectTo=${encodeURIComponent(req.nextUrl.href)}`,
114
114
-
req.url,
115
115
-
),
120
120
+
req.url
121
121
+
)
116
122
);
117
123
}
118
124
···
120
126
return NextResponse.redirect(
121
127
new URL(
122
128
`/app/login?redirectTo=${encodeURIComponent(req.nextUrl.href)}`,
123
123
-
req.url,
124
124
-
),
129
129
+
req.url
130
130
+
)
125
131
);
126
132
}
127
133
···
140
146
141
147
if (hasWorkspaceSlug) {
142
148
const hasAccessToWorkspace = allowedWorkspaces.find(
143
143
-
({ workspace }) => workspace.slug === workspaceSlug,
149
149
+
({ workspace }) => workspace.slug === workspaceSlug
144
150
);
145
151
if (hasAccessToWorkspace) {
146
152
const workspaceCookie = req.cookies.get("workspace-slug")?.value;
···
158
164
const firstWorkspace = allowedWorkspaces[0].workspace;
159
165
const { slug } = firstWorkspace;
160
166
return NextResponse.redirect(
161
161
-
new URL(`/app/${slug}/monitors`, req.url),
167
167
+
new URL(`/app/${slug}/monitors`, req.url)
162
168
);
163
169
}
164
170
}