mirror of
https://github.com/coollabsio/coolify-examples.git
synced 2026-02-18 21:38:58 +00:00
Refactor image loader URL and optimize image in loader.js
This commit is contained in:
@@ -2,16 +2,22 @@
|
|||||||
|
|
||||||
export default function myImageLoader({ src, width, quality }) {
|
export default function myImageLoader({ src, width, quality }) {
|
||||||
const isLocal = !src.startsWith('http');
|
const isLocal = !src.startsWith('http');
|
||||||
|
const query = new URLSearchParams();
|
||||||
|
|
||||||
|
const imageOptimizationApi = 'https://images.coollabs.io/o';
|
||||||
|
// Your NextJS application URL
|
||||||
|
const baseUrl = 'https://xoos0kk.heyandras.dev';
|
||||||
|
|
||||||
|
const fullSrc = `${baseUrl}${src}`;
|
||||||
|
|
||||||
|
if (width) query.set('width', width);
|
||||||
|
if (quality) query.set('quality', quality);
|
||||||
|
|
||||||
if (isLocal && process.env.NODE_ENV === 'development') {
|
if (isLocal && process.env.NODE_ENV === 'development') {
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
const query = new URLSearchParams();
|
|
||||||
if (width) query.set('width', width);
|
|
||||||
if (quality) query.set('quality', quality);
|
|
||||||
if (isLocal) {
|
if (isLocal) {
|
||||||
const baseUrl = 'https://xoos0kk.heyandras.dev';
|
return `${imageOptimizationApi}/${fullSrc}?${query.toString()}`;
|
||||||
const fullSrc = `${baseUrl}${src}`;
|
|
||||||
return `https://images.coollabs.io/o/${fullSrc}?${query.toString()}`;
|
|
||||||
}
|
}
|
||||||
return `https://images.coollabs.io/o/${src}?${query.toString()}`;
|
return `${imageOptimizationApi}/${src}?${query.toString()}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user