Skip to content

Commit 422a6c2

Browse files
committed
fix endpoint path style detection
1 parent 0b9b2c1 commit 422a6c2

File tree

1 file changed

+6
-9
lines changed
  • packages/web-backend/src/S3Buckets

1 file changed

+6
-9
lines changed

packages/web-backend/src/S3Buckets/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,17 @@ export class S3Buckets extends Effect.Service<S3Buckets>()("S3Buckets", {
4545
requestStreamBufferSize: 16 * 1024,
4646
});
4747

48-
const endpointIsPathStyle = (endpoint: string) => {
48+
const endpointIsPathStyle = (endpoint: string, bucket: string) => {
4949
try {
5050
const { hostname } = new URL(endpoint);
51-
return (
52-
hostname === "s3.amazonaws.com" ||
53-
hostname.endsWith(".s3.amazonaws.com")
54-
);
51+
return !hostname.startsWith(`${bucket}.s3`)
5552
} catch {
5653
// If endpoint can't be parsed as a URL, fall back to false for safety
57-
return false;
54+
return true;
5855
}
5956
};
6057

61-
const createBucketClient = async (bucket: S3Bucket.S3Bucket) => {
58+
const createBucketClient = async (bucket: S3Bucket.S3Bucket, name: string) => {
6259
const endpoint = await (() => {
6360
const v = bucket.endpoint.pipe(Option.getOrUndefined);
6461
if (!v) return;
@@ -74,7 +71,7 @@ export class S3Buckets extends Effect.Service<S3Buckets>()("S3Buckets", {
7471
},
7572
forcePathStyle:
7673
Option.fromNullable(endpoint).pipe(
77-
Option.map(endpointIsPathStyle),
74+
Option.map(e => endpointIsPathStyle(e, name)),
7875
Option.getOrNull,
7976
) ?? true,
8077
useArnRegion: false,
@@ -154,7 +151,7 @@ export class S3Buckets extends Effect.Service<S3Buckets>()("S3Buckets", {
154151
);
155152

156153
const client = yield* Effect.promise(() =>
157-
createBucketClient(customBucket),
154+
createBucketClient(customBucket, bucket),
158155
);
159156
const provider = Layer.succeed(S3BucketClientProvider, {
160157
getInternal: Effect.succeed(client),

0 commit comments

Comments
 (0)