Skip to content

Commit 9c4f3c4

Browse files
committed
Bypass sharp in docker hosted environment #295
1 parent af277d8 commit 9c4f3c4

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ADD client/package.json client/package-lock.json ./
1414
RUN npm install
1515

1616
ADD client /app/
17+
RUN cp .env.docker .env
1718
RUN npm run build
1819

1920
# syntax=docker/dockerfile:1.3-labs

client/.env.docker

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ NUXT_PUBLIC_H_CAPTCHA_SITE_KEY=
1111
NUXT_PUBLIC_PAID_PLANS_ENABLED=
1212
NUXT_PUBLIC_S3_ENABLED=
1313
NUXT_API_SECRET=
14+
NUXT_PUBLIC_USE_NULL_IMAGE_PROVIDER=yes

client/lib/null-image-provider.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { joinURL } from 'ufo'
2+
import { createOperationsGenerator } from '#image'
3+
4+
const operationsGenerator = createOperationsGenerator()
5+
6+
export const getImage = (
7+
src,
8+
{ modifiers = {}, baseURL } = {}
9+
) => {
10+
11+
if (!baseURL) {
12+
// also support runtime config
13+
baseURL = useRuntimeConfig().public.siteUrl
14+
}
15+
16+
const operations = operationsGenerator(modifiers)
17+
18+
return {
19+
url: joinURL(baseURL, src + (operations ? '?' + operations : '')),
20+
}
21+
}
22+

client/nuxt.config.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,18 @@ export default defineNuxtConfig({
6464
}
6565
}
6666
},
67-
image: {
68-
quality: 95,
69-
},
67+
image: (
68+
runtimeConfig.public.useNullImageProvider ? {
69+
provider: 'null',
70+
providers: {
71+
null: {
72+
provider: '~/lib/null-image-provider.js',
73+
}
74+
}
75+
} : {
76+
quality: 95,
77+
}
78+
),
7079
sourcemap: true,
7180
vite: {
7281
plugins: [

client/runtimeConfig.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export default {
1212
s3Enabled: process.env.NUXT_PUBLIC_S3_ENABLED || false,
1313
paidPlansEnabled: process.env.NUXT_PUBLIC_PAID_PLANS_ENABLED || false,
1414
customDomainsEnabled: process.env.NUXT_PUBLIC_CUSTOM_DOMAINS_ENABLED || false,
15-
15+
useNullImageProvider: (
16+
process.env.NUXT_PUBLIC_USE_NULL_IMAGE_PROVIDER == 'yes'
17+
),
18+
1619
// Config within public will be also exposed to the client
1720
SENTRY_DSN_PUBLIC: process.env.SENTRY_DSN_PUBLIC,
1821
SENTRY_TRACES_SAMPLE_RATE: parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE ?? '0'),

0 commit comments

Comments
 (0)