diff --git a/src/libs/redirect.ts b/src/libs/redirect.ts index 586de08..b2c9aa7 100644 --- a/src/libs/redirect.ts +++ b/src/libs/redirect.ts @@ -8,7 +8,7 @@ export function redirect( ctx: RouterContext, userAgent: UserAgent, ref: string = "master", -): void { +): boolean { const repository = getRepository(); const url = join( new URL("https://github.com"), @@ -19,8 +19,9 @@ export function redirect( repository.path, ); - if (userAgent?.browser.name) { - ctx.response.status = STATUS_CODE.PermanentRedirect; - ctx.response.redirect(url); - } + if (!userAgent?.browser.name) return false; + + ctx.response.status = STATUS_CODE.PermanentRedirect; + ctx.response.redirect(url); + return true; } diff --git a/src/router.ts b/src/router.ts index 0664a00..a9f7f51 100644 --- a/src/router.ts +++ b/src/router.ts @@ -5,12 +5,10 @@ export const router = new Router(); router .get("/", async (ctx: RouterContext) => { ctx.response.type = "text/plain"; - await getContent(ctx); - redirect(ctx, ctx.request.userAgent); + if (!redirect(ctx, ctx.request.userAgent)) await getContent(ctx); }) .get("/:ref", async (ctx: RouterContext) => { const ref: string | undefined = ctx.params.ref; ctx.response.type = "text/plain"; - await getContent(ctx, ref); - redirect(ctx, ctx.request.userAgent, ref); + if (!redirect(ctx, ctx.request.userAgent, ref)) await getContent(ctx, ref); });