aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-12-06 21:42:05 -0800
committerFuwn <[email protected]>2023-12-06 21:42:05 -0800
commitaef257cc7fe12c91c290efca0724a0264ffbc67d (patch)
tree7b39e5745191783124d84ca268c5da5407e055c8 /src/routes/api
parentfeat(manga): add fetch delay (diff)
downloaddue.moe-aef257cc7fe12c91c290efca0724a0264ffbc67d.tar.xz
due.moe-aef257cc7fe12c91c290efca0724a0264ffbc67d.zip
feat(proxy): proxy all content
Diffstat (limited to 'src/routes/api')
-rw-r--r--src/routes/api/proxy/+server.ts20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/routes/api/proxy/+server.ts b/src/routes/api/proxy/+server.ts
index 1c4a25dc..c4bf74a6 100644
--- a/src/routes/api/proxy/+server.ts
+++ b/src/routes/api/proxy/+server.ts
@@ -1,2 +1,18 @@
-export const GET = async ({ url }) =>
- new Response(await (await fetch(url.searchParams.get('url') as string)).blob());
+export const GET = async ({ url }) => {
+ const response = await fetch(url.searchParams.get('url') as string);
+ const contentType = response.headers.get('content-type') as string;
+
+ if (contentType.includes('application/json')) {
+ return Response.json(await response.json(), {
+ headers: { 'Content-Type': 'application/json' }
+ });
+ } else if (contentType.includes('text/html') || contentType.includes('text/plain')) {
+ return new Response(await response.text(), {
+ headers: { 'Content-Type': contentType }
+ });
+ } else {
+ return new Response(await response.blob(), {
+ headers: { 'Content-Type': contentType }
+ });
+ }
+};