Skip to content

Commit

Permalink
Remove obsolete url params.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gandalf-the-Grey committed May 4, 2024
1 parent 36ac519 commit 2d17ab1
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ app.use(async (ctx, next) => {
// redirect to home page/feed if known account
if (ctx.method === 'GET' && ctx.url === '/' && ctx.session.a) {
ctx.status = 302;
//this.redirect(`/@${this.session.a}/feed`);
ctx.redirect(`/trending/my`);
return;
}
Expand Down Expand Up @@ -185,35 +184,7 @@ app.use(async (ctx, next) => {
}
}

// this.url is a relative URL, it does not include the scheme
const [pathString, queryString] = ctx.url.split('?');
const urlParams = new URLSearchParams(queryString);

let paramFound = false;
if (ctx.url.indexOf('?') !== -1) {
const paramsToProcess = ['ch', 'cn', 'r'];

paramsToProcess.forEach((paramToProcess) => {
if (urlParams.has(paramToProcess)) {
const paramValue = urlParams.get(paramToProcess);
if (paramValue) {
paramFound = true;
ctx.session[paramToProcess] = paramValue;
urlParams.delete(paramToProcess);
}
}
});
}

if (paramFound) {
const newQueryString = urlParams.toString();
const redir = `${pathString.replace(/\/\//g, '/')}${newQueryString ? `?${newQueryString}` : ''}`;

ctx.status = 302;
ctx.redirect(redir);
} else {
await next();
}
await next(); // Proceed with the next middleware if no conditions were met
});

// load production middleware
Expand Down

0 comments on commit 2d17ab1

Please sign in to comment.