File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 11import { multiParser } from "https://deno.land/x/multiparser@0.114.0/mod.ts" ;
2+ import { isURL } from "https://deno.land/x/is_url/mod.ts" ;
3+
24import { headers } from "./headers.ts" ;
35import handler from "./utils.ts" ;
46const urlBase = Deno . env . get ( "URL_BASE" ) || "" ;
57const { generateShortUrl } = handler ( ) ;
68
9+ /**
10+ * Redirects to the long URL associated with the given short URL.
11+ *
12+ * @param request - The incoming HTTP request.
13+ * @returns A redirection response to the long URL or an error message.
14+ * @throws If an error occurs while fetching the long URL from Supabase.
15+ *
16+ * @example
17+ * // Example usage
18+ * curl -X GET https://your-api-url/shortUrl
19+ */
720export default async ( request : Request ) : Promise < Response > => {
821 try {
922 const formData = await multiParser ( request ) ;
@@ -16,6 +29,13 @@ export default async (request: Request): Promise<Response> => {
1629 } ) ;
1730 }
1831
32+ if ( ! isURL ( url ) ) {
33+ return new Response ( JSON . stringify ( { error : "Invalid URL provided" } ) , {
34+ status : 400 ,
35+ headers,
36+ } ) ;
37+ }
38+
1939 let shortUrl = await generateShortUrl ( url ) ;
2040 shortUrl = urlBase + shortUrl ;
2141
You can’t perform that action at this time.
0 commit comments