Skip to content

Commit 73e70c7

Browse files
committed
fix: auto webp and avif images
fix: accept header
1 parent 834a5e2 commit 73e70c7

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

docker-compose-dev.yaml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
services:
2-
# api:
3-
# image: oven/bun:alpine
4-
# working_dir: /app
5-
# ports:
6-
# - "3000:3000"
7-
# environment:
8-
# - NODE_ENV=development
9-
# volumes:
10-
# - .:/app
11-
# command: "bun run --watch /app/index.js"
122
imgproxy:
133
image: darthsim/imgproxy
144
ports:
155
- "8888:8080"
166
environment:
177
- IMGPROXY_ENABLE_WEBP_DETECTION=true
8+
- IMGPROXY_ENABLE_AVIF_DETECTION=true
9+
- IMGPROXY_PREFERRED_FORMATS=webp,avif,jpeg,png,gif
1810
- IMGPROXY_JPEG_PROGRESSIVE=true
1911
- IMGPROXY_USE_ETAG=true

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ services:
1919
image: darthsim/imgproxy
2020
environment:
2121
- IMGPROXY_ENABLE_WEBP_DETECTION=true
22+
- IMGPROXY_ENABLE_AVIF_DETECTION=true
2223
- IMGPROXY_JPEG_PROGRESSIVE=true
2324
- IMGPROXY_USE_ETAG=true
2425
healthcheck:

index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const allowedDomains = process?.env?.ALLOWED_REMOTE_DOMAINS.split(",") || ["*"];
1+
const version = "0.0.3"
2+
3+
const allowedDomains = process?.env?.ALLOWED_REMOTE_DOMAINS?.split(",") || ["*"];
24
const imgproxyUrl = process?.env?.IMGPROXY_URL || "http://imgproxy:8080";
3-
const version = "0.0.2"
5+
46
Bun.serve({
57
port: 3000,
68
async fetch(req) {
@@ -13,7 +15,6 @@ Bun.serve({
1315
});
1416
}
1517

16-
1718
if (url.pathname === "/health") {
1819
return new Response("OK");
1920
};
@@ -33,8 +34,12 @@ async function resize(url) {
3334
const height = url.searchParams.get("height") || 0;
3435
const quality = url.searchParams.get("quality") || 75;
3536
try {
36-
const url = `${imgproxyUrl}/${preset}/resize:fill:${width}:${height}/q:${quality}/plain/${src}@webp`
37-
const image = await fetch(url)
37+
const url = `${imgproxyUrl}/${preset}/resize:fill:${width}:${height}/q:${quality}/plain/${src}`
38+
const image = await fetch(url , {
39+
headers: {
40+
"Accept": "image/avif,image/webp,image/*,",
41+
}
42+
})
3843
const headers = new Headers(image.headers);
3944
headers.set("Server", "NextImageTransformation");
4045
return new Response(image.body, {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"start": "bun run ./index.js"
88
},
99
"devDependencies": {},
10-
"peerDependencies": {}
10+
"peerDependencies": {},
11+
"dependencies": {}
1112
}

0 commit comments

Comments
 (0)