Skip to content

Commit 99fbf9b

Browse files
committed
parse endpoint as url
1 parent 6d83a14 commit 99fbf9b

File tree

1 file changed

+12
-2
lines changed
  • packages/web-backend/src/S3Buckets

1 file changed

+12
-2
lines changed

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

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

48-
const endpointIsPathStyle = (endpoint: string) =>
49-
endpoint.endsWith("s3.amazonaws.com");
48+
const endpointIsPathStyle = (endpoint: string) => {
49+
try {
50+
const { hostname } = new URL(endpoint);
51+
return (
52+
hostname === "s3.amazonaws.com" ||
53+
hostname.endsWith(".s3.amazonaws.com")
54+
);
55+
} catch {
56+
// If endpoint can't be parsed as a URL, fall back to false for safety
57+
return false;
58+
}
59+
};
5060

5161
const createBucketClient = async (bucket: S3Bucket.S3Bucket) => {
5262
const endpoint = await (() => {

0 commit comments

Comments
 (0)