Skip to content

Commit

Permalink
Handle relative paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphsps committed Aug 19, 2024
1 parent 4ecbbe0 commit 47f59e7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const handleRequest = async (request: Request, _env: {}, ctx: ExecutionContext):
const url = new URL(request.url);

const params = url.searchParams;
const imageUrl = params.get('url');
let imageUrl = params.get('url');
if (imageUrl?.startsWith('/')) {
imageUrl = `https://demo.nordcom.io${imageUrl}`;
}
if (!imageUrl || !isValidUrl(imageUrl)) {
return new Response('url is required', { status: 400 });
}
Expand Down Expand Up @@ -88,7 +91,7 @@ const handleRequest = async (request: Request, _env: {}, ctx: ExecutionContext):
});*/
const response = new Response(image, {
headers: {
'Content-Type': contentType!,//`image/${format}`,
'Content-Type': contentType!, //`image/${format}`,
'Cache-Control': 'public, max-age=31536000, immutable',
date: new Date().toUTCString(),
},
Expand Down

0 comments on commit 47f59e7

Please sign in to comment.