diff --git a/src/cdn/util/S3Storage.ts b/src/cdn/util/S3Storage.ts index 22afd88e4..fb378836d 100644 --- a/src/cdn/util/S3Storage.ts +++ b/src/cdn/util/S3Storage.ts @@ -33,10 +33,11 @@ export class S3Storage implements Storage { private region: string, private bucket: string, private endpoint: string, + private forcePathStyle: boolean, private basePath?: string, ) { const { S3 } = require("@aws-sdk/client-s3"); - this.client = new S3({ region: region, endpoint: endpoint }); + this.client = new S3({ region: region, endpoint: endpoint, forcePathStyle: forcePathStyle }); } isFile(path: string): Promise { return this.exists(path); diff --git a/src/cdn/util/Storage.ts b/src/cdn/util/Storage.ts index f90d5d1b7..8b7602cbc 100644 --- a/src/cdn/util/Storage.ts +++ b/src/cdn/util/Storage.ts @@ -82,8 +82,15 @@ if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) { location = undefined; } + // if false, the bucket name is used as a subdomain + const forcePathStyle = process.env.STORAGE_FORCE_PATH_STYLE === "true"; + + if (process.env.STORAGE_FORCE_PATH_STYLE === undefined) { + console.warn(`[CDN] STORAGE_FORCE_PATH_STYLE unconfigured for S3 provider, defaulting to use virtual-hosted style...`); + } + const { S3Storage } = require("./S3Storage"); - storage = new S3Storage(region, bucket, endpoint, location); + storage = new S3Storage(region, bucket, endpoint, forcePathStyle, location); } export { storage };