From 50c7da9872fcb12482d1290ea3c1f2d3101193a3 Mon Sep 17 00:00:00 2001 From: ohmwraith Date: Fri, 24 Apr 2026 04:33:21 +0300 Subject: [PATCH] Implement S3 force path-style support --- src/cdn/util/S3Storage.ts | 3 ++- src/cdn/util/Storage.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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 };