Skip to content

Commit 97b8cae

Browse files
committed
introduce S3_PUBLIC_GATEWAY
This will fix the problem of differing domains in docker-compose locally but it also sets the ground for a later use of a image resize service.
1 parent f62352d commit 97b8cae

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

backend/src/config/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ const s3 = {
102102
AWS_ENDPOINT: env.AWS_ENDPOINT,
103103
AWS_REGION: env.AWS_REGION,
104104
AWS_BUCKET: env.AWS_BUCKET,
105+
S3_PUBLIC_GATEWAY: env.S3_PUBLIC_GATEWAY,
105106
S3_CONFIGURED:
106107
env.AWS_ACCESS_KEY_ID &&
107108
env.AWS_SECRET_ACCESS_KEY &&
108109
env.AWS_ENDPOINT &&
109110
env.AWS_REGION &&
110-
env.AWS_BUCKET,
111+
env.AWS_BUCKET &&
112+
env.S3_PUBLIC_GATEWAY,
111113
}
112114

113115
const options = {

backend/src/graphql/resolvers/images/images.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ export interface ImageInput {
3131
}
3232

3333
export interface Images {
34+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3435
deleteImage: (resource, relationshipType, opts: DeleteImageOpts) => Promise<any>
36+
3537
mergeImage: (
3638
resource,
3739
relationshipType,
3840
imageInput: ImageInput | null | undefined,
3941
opts: MergeImageOpts,
42+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4043
) => Promise<any>
4144
}
4245

backend/src/graphql/resolvers/images/imagesS3.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,21 @@ import type { FileUpload } from 'graphql-upload'
3030
export const images = (
3131
config: Pick<
3232
typeof CONFIG,
33-
'AWS_ACCESS_KEY_ID' | 'AWS_SECRET_ACCESS_KEY' | 'AWS_ENDPOINT' | 'AWS_REGION' | 'AWS_BUCKET'
33+
| 'AWS_ACCESS_KEY_ID'
34+
| 'AWS_SECRET_ACCESS_KEY'
35+
| 'AWS_ENDPOINT'
36+
| 'AWS_REGION'
37+
| 'AWS_BUCKET'
38+
| 'S3_PUBLIC_GATEWAY'
3439
>,
3540
) => {
3641
// const widths = [34, 160, 320, 640, 1024]
37-
const { AWS_BUCKET: Bucket } = config
42+
const { AWS_BUCKET: Bucket, S3_PUBLIC_GATEWAY } = config
3843

3944
const { AWS_ENDPOINT, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY } = config
40-
if (!(AWS_ENDPOINT && AWS_ACCESS_KEY_ID && AWS_SECRET_ACCESS_KEY)) {
45+
if (
46+
!(AWS_ENDPOINT && AWS_ACCESS_KEY_ID && AWS_SECRET_ACCESS_KEY && Bucket && S3_PUBLIC_GATEWAY)
47+
) {
4148
throw new Error('Missing AWS credentials.')
4249
}
4350
const s3 = new S3Client({
@@ -174,7 +181,9 @@ export const images = (
174181
if (!Location) {
175182
throw new Error('File upload did not return `Location`')
176183
}
177-
return Location
184+
const publicLocation = new URL(S3_PUBLIC_GATEWAY)
185+
publicLocation.pathname = new URL(Location).pathname
186+
return publicLocation.href
178187
}
179188

180189
const s3Delete: FileDeleteCallback = async (url) => {

docker-compose.override.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ services:
3333
- SMTP_PORT=1025
3434
- SMTP_HOST=mailserver
3535
- AWS_ENDPOINT=http://minio:9000
36+
- S3_PUBLIC_GATEWAY=http://localhost:9000
3637
volumes:
3738
- ./backend:/app
3839

0 commit comments

Comments
 (0)