tangled
alpha
login
or
join now
openstatus.dev
/
openstatus
5
fork
atom
Openstatus
www.openstatus.dev
5
fork
atom
overview
issues
pulls
pipelines
fix: https
Maximilian Kaske
6 months ago
85cb29e8
c705333e
+14
-11
2 changed files
expand all
collapse all
unified
split
apps
web
next.config.js
src
middleware.ts
+5
-4
apps/web/next.config.js
···
65
65
];
66
66
},
67
67
async rewrites() {
68
68
-
const NEW_HOST =
68
68
+
const HOST =
69
69
process.env.NODE_ENV === "development" ? "localhost:3001" : "stpg.dev";
70
70
+
const PROTOCOL = process.env.NODE_ENV === "development" ? "http" : "https";
70
71
return {
71
72
beforeFiles: [
72
73
// Proxy app subdomain to /app
···
90
91
value: "(?<slug>[^.]+)\\.(openstatus\\.dev|localhost)",
91
92
},
92
93
],
93
93
-
destination: `http://${NEW_HOST}/_next/:path*`,
94
94
+
destination: `${PROTOCOL}://${HOST}/_next/:path*`,
94
95
},
95
96
// New design: proxy app routes to external host with slug prefix
96
97
{
···
103
104
},
104
105
],
105
106
// NOTE: might be different on prod and localhost (without :slug)
106
106
-
destination: `http://${NEW_HOST}/:slug/:path*`,
107
107
+
destination: `${PROTOCOL}://${HOST}/:slug/:path*`,
107
108
},
108
109
],
109
110
};
···
137
138
138
139
// Automatically tree-shake Sentry logger statements to reduce bundle size
139
140
disableLogger: true,
140
140
-
}
141
141
+
},
141
142
);
+9
-7
apps/web/src/middleware.ts
···
78
78
try {
79
79
const redis = Redis.fromEnv();
80
80
const cache = await redis.get(`page:${subdomain}`);
81
81
+
console.log({ cache });
81
82
// Determine legacy flag from cache
82
83
mode = cache ? "new" : "legacy";
83
84
} catch {
85
85
+
console.log("error getting cache");
84
86
mode = "legacy";
85
87
}
86
88
}
···
110
112
}
111
113
112
114
const isPublicAppPath = publicAppPaths.some((path) =>
113
113
-
pathname.startsWith(path)
115
115
+
pathname.startsWith(path),
114
116
);
115
117
116
118
if (!req.auth && pathname.startsWith("/app/invite")) {
117
119
return NextResponse.redirect(
118
120
new URL(
119
121
`/app/login?redirectTo=${encodeURIComponent(req.nextUrl.href)}`,
120
120
-
req.url
121
121
-
)
122
122
+
req.url,
123
123
+
),
122
124
);
123
125
}
124
126
···
126
128
return NextResponse.redirect(
127
129
new URL(
128
130
`/app/login?redirectTo=${encodeURIComponent(req.nextUrl.href)}`,
129
129
-
req.url
130
130
-
)
131
131
+
req.url,
132
132
+
),
131
133
);
132
134
}
133
135
···
146
148
147
149
if (hasWorkspaceSlug) {
148
150
const hasAccessToWorkspace = allowedWorkspaces.find(
149
149
-
({ workspace }) => workspace.slug === workspaceSlug
151
151
+
({ workspace }) => workspace.slug === workspaceSlug,
150
152
);
151
153
if (hasAccessToWorkspace) {
152
154
const workspaceCookie = req.cookies.get("workspace-slug")?.value;
···
164
166
const firstWorkspace = allowedWorkspaces[0].workspace;
165
167
const { slug } = firstWorkspace;
166
168
return NextResponse.redirect(
167
167
-
new URL(`/app/${slug}/monitors`, req.url)
169
169
+
new URL(`/app/${slug}/monitors`, req.url),
168
170
);
169
171
}
170
172
}