Skip to content

Commit 77c6083

Browse files
committed
feat: catch unchanged urls to prevent redirect loop
1 parent 8c97433 commit 77c6083

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pages/[[...params]].js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ export async function getServerSideProps({ req, res, query }) {
4848

4949
let baseUrl = host;
5050

51-
// for local testing
52-
if (baseUrl === "localhost:3000") {
53-
baseUrl = siteParams.urlReplace.real;
54-
}
5551
siteParams.urlReplace.fake.forEach((u) => {
5652
baseUrl = baseUrl.replace(u, siteParams.urlReplace.real);
5753
});
5854

55+
// catch local testing, or if the url hasn't been changed for some reason
56+
if (baseUrl === "localhost:3000" || baseUrl === host) {
57+
baseUrl = siteParams.urlReplace.real;
58+
console.log(`[WARN]: unmodified url https://${host}/${path}, replacing with https://${baseUrl}/${path}`);
59+
}
60+
5961
const path = query.params?.join("/") || "";
6062

6163
const actualUrl = `https://${baseUrl}/${path}`;

0 commit comments

Comments
 (0)