Skip to content

Commit

Permalink
refactor(redirect): Use URL library
Browse files Browse the repository at this point in the history
Because of processing URL not directory path.
  • Loading branch information
5ouma committed Jun 12, 2024
1 parent c2a7fb9 commit c989260
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@std/fmt": "jsr:@std/[email protected]",
"@std/http": "jsr:@std/[email protected]",
"@std/http/user-agent": "jsr:@std/http@~0.223/user-agent",
"@std/path": "jsr:@std/path@0.225.2"
"@std/url": "jsr:@std/url@0.224.1"
},
"deploy": {
"project": "reproxy",
Expand Down
20 changes: 14 additions & 6 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions src/libs/redirect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RouterContext } from "@oak/oak";
import { STATUS_CODE } from "@std/http/status";
import { UserAgent } from "@std/http/user-agent";
import { join } from "@std/path";
import { join } from "@std/url";
import { getRepository } from "./env.ts";

export function redirect<R extends string>(
Expand All @@ -10,16 +10,14 @@ export function redirect<R extends string>(
ref: string = "HEAD"
): void {
const repository = getRepository();
const url: string =
"https://" +
join(
"github.com",
repository.owner,
repository.name,
"blob",
ref,
repository.path
);
const url = join(
new URL("https://github.com"),
repository.owner,
repository.name,
"blob",
ref,
repository.path
);

if (userAgent?.browser.name) {
ctx.response.status = STATUS_CODE.PermanentRedirect;
Expand Down

0 comments on commit c989260

Please sign in to comment.