Skip to content

Commit

Permalink
feat: add add function to generate full url
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucky3028 committed Sep 21, 2023
1 parent 0297333 commit 59510cb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/auto-run-ac-api/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { HonoRequest } from 'hono';
import { customAlphabet } from 'nanoid';
import { alphanumeric } from 'nanoid-dictionary';

Expand All @@ -13,3 +14,14 @@ export const parseDecimalInt = (str: string) => parseInt(str, 10);
* @returns 英数字からなるnanoid。英字には大文字小文字いずれも含まれる
*/
export const nanoid = () => customAlphabet(alphanumeric, 20)();

/**
* HonoRequestからクエリ文字列を抜かしたURLを取得する
* @param req Request
* @returns クエリ文字列を抜かしたURL
*/
export const getUrl = (req: HonoRequest) => {
const url = new URL(req.url);

return `${url.origin}${url.pathname}`;
};

0 comments on commit 59510cb

Please sign in to comment.