feat: change img proxy configuration
All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 8s
Build & Deploy / 🧪 QA (push) Successful in 1m56s
Build & Deploy / 🏗️ Build (push) Successful in 4m5s
Build & Deploy / 🚀 Deploy (push) Successful in 1m19s
Build & Deploy / 🧪 Smoke Test (push) Successful in 48s
Build & Deploy / 🛡️ Quality Gates (push) Successful in 1m39s
Build & Deploy / ⚡ Lighthouse (push) Successful in 5m51s
Build & Deploy / ♿ WCAG (push) Successful in 7m0s
Build & Deploy / 🔔 Notify (push) Successful in 2s
All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 8s
Build & Deploy / 🧪 QA (push) Successful in 1m56s
Build & Deploy / 🏗️ Build (push) Successful in 4m5s
Build & Deploy / 🚀 Deploy (push) Successful in 1m19s
Build & Deploy / 🧪 Smoke Test (push) Successful in 48s
Build & Deploy / 🛡️ Quality Gates (push) Successful in 1m39s
Build & Deploy / ⚡ Lighthouse (push) Successful in 5m51s
Build & Deploy / ♿ WCAG (push) Successful in 7m0s
Build & Deploy / 🔔 Notify (push) Successful in 2s
This commit is contained in:
3
.env
3
.env
@@ -35,4 +35,5 @@ GATEKEEPER_PASSWORD=klz2026
|
||||
COOKIE_DOMAIN=localhost
|
||||
INFRA_DIRECTUS_URL=http://localhost:8059
|
||||
INFRA_DIRECTUS_TOKEN=59fb8f4c1a51b18fe28ad947f713914e
|
||||
GATEKEEPER_ORIGIN=http://klz.localhost
|
||||
GATEKEEPER_ORIGIN=http://klz.localhost
|
||||
OPENROUTER_API_KEY=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
|
||||
@@ -155,7 +155,7 @@ services:
|
||||
- default
|
||||
|
||||
klz-imgproxy:
|
||||
image: darthsim/imgproxy:latest
|
||||
image: registry.infra.mintel.me/mintel/image-processor:latest
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- default
|
||||
@@ -165,12 +165,10 @@ services:
|
||||
- "cms.klz.localhost:host-gateway"
|
||||
- "host.docker.internal:host-gateway"
|
||||
environment:
|
||||
OPENROUTER_API_KEY: ${OPENROUTER_API_KEY}
|
||||
# IMGPROXY_URL_MAPPING is not used by our new service yet, but we can keep it for future parity if we add it back
|
||||
IMGPROXY_URL_MAPPING: "${NEXT_PUBLIC_BASE_URL}:http://klz-app:3000,${DIRECTUS_URL}:http://klz-cms:8055"
|
||||
IMGPROXY_USE_ETAG: "true"
|
||||
IMGPROXY_MAX_SRC_RESOLUTION: 20
|
||||
IMGPROXY_IGNORE_SSL_ERRORS: "true"
|
||||
IMGPROXY_LOG_LEVEL: debug
|
||||
IMGPROXY_ALLOW_LOCAL_NETWORKS: "true"
|
||||
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
|
||||
@@ -39,34 +39,21 @@ export function getImgproxyUrl(src: string, options: ImgproxyOptions = {}): stri
|
||||
// Also handle direct container names if needed
|
||||
}
|
||||
|
||||
const {
|
||||
width = 0,
|
||||
height = 0,
|
||||
resizing_type = 'fit',
|
||||
gravity = 'sm', // Default to smart gravity
|
||||
enlarge = false,
|
||||
extension = '',
|
||||
} = options;
|
||||
const { width = 0, height = 0, enlarge = false, extension = '' } = options;
|
||||
|
||||
// Processing options
|
||||
// Format: /rs:<type>:<width>:<height>:<enlarge>/g:<gravity>
|
||||
const processingOptions = [
|
||||
`rs:${resizing_type}:${width}:${height}:${enlarge ? 1 : 0}`,
|
||||
`g:${gravity}`,
|
||||
].join('/');
|
||||
let quality = 80;
|
||||
if (extension) quality = 90;
|
||||
|
||||
// Using Base64 encoding for the source URL.
|
||||
// This completely eliminates any risk of intermediate proxies (Traefik/Next.js)
|
||||
// URL-decoding the path, which corrupts the double-slash (// to /) and causes 403 errors.
|
||||
// Imgproxy expects URL-safe Base64 (RFC 4648) without padding.
|
||||
const b64 =
|
||||
typeof window === 'undefined'
|
||||
? Buffer.from(absoluteSrc).toString('base64')
|
||||
: btoa(unescape(encodeURIComponent(absoluteSrc)));
|
||||
// Re-map imgproxy URL to our new parameter structure
|
||||
// e.g. /process?url=...&w=...&h=...&q=...&format=...
|
||||
const queryParams = new URLSearchParams({
|
||||
url: absoluteSrc,
|
||||
});
|
||||
|
||||
const urlSafeB64 = b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
||||
if (width > 0) queryParams.set('w', width.toString());
|
||||
if (height > 0) queryParams.set('h', height.toString());
|
||||
if (extension) queryParams.set('format', extension.replace('.', ''));
|
||||
if (quality) queryParams.set('q', quality.toString());
|
||||
|
||||
const suffix = extension ? `.${extension}` : '';
|
||||
|
||||
return `${baseUrl}/unsafe/${processingOptions}/${urlSafeB64}${suffix}`;
|
||||
return `${baseUrl}/process?${queryParams.toString()}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user