Skip to content

fix: allow custom S3 enpoint via ENV variable#17

Open
valtlfelipe wants to merge 1 commit intozmeyer44:mainfrom
valtlfelipe:fix/aws-endpoint
Open

fix: allow custom S3 enpoint via ENV variable#17
valtlfelipe wants to merge 1 commit intozmeyer44:mainfrom
valtlfelipe:fix/aws-endpoint

Conversation

@valtlfelipe
Copy link
Copy Markdown

@valtlfelipe valtlfelipe commented Apr 7, 2026

Allow custom S3 enpoint via ENV variable For S3-compatible services. For custom s3 we should use virtual-hosted–style URLs.

Tested and validated on railway.

Here is the templatwe by the way: https://railway.com/deploy/locker-1?referralCode=ca9X8b&utm_medium=integration&utm_source=template&utm_campaign=generic

Can I add the button to the readme?

[![Deploy on Railway](https://railway.com/button.svg)](https://railway.com/deploy/locker-1?referralCode=ca9X8b&utm_medium=integration&utm_source=template&utm_campaign=generic)

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 7, 2026

@valtlfelipe is attempting to deploy a commit to the Zach's Projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 7, 2026

Greptile Summary

Adds support for S3-compatible storage services by reading a custom endpoint from AWS_ENDPOINT_URL and enabling forcePathStyle when a custom endpoint is set. The approach is correct; one minor edge case exists where a trailing slash on the endpoint value would produce double-slash object URLs.

Confidence Score: 5/5

Safe to merge — the core change is correct and functional for S3-compatible services

All findings are P2 style suggestions. The forcePathStyle logic is correct for S3-compatible services and the trailing-slash edge case is an uncommon misconfiguration.

packages/storage/src/s3.ts — minor trailing-slash edge case in URL construction

Important Files Changed

Filename Overview
packages/storage/src/s3.ts Adds AWS_ENDPOINT_URL env var support with forcePathStyle; trailing-slash edge case in URL construction
.env.example Documents the new optional AWS_ENDPOINT_URL environment variable
turbo.json Adds AWS_ENDPOINT_URL to Turborepo's env passthrough list

Sequence Diagram

sequenceDiagram
    participant App
    participant S3StorageAdapter
    participant S3Client
    participant Storage as Storage (AWS S3 or Compatible)

    App->>S3StorageAdapter: upload(path, data, contentType)
    Note over S3StorageAdapter: Uses endpoint from AWS_ENDPOINT_URL (if set)
    S3StorageAdapter->>S3Client: PutObjectCommand(Bucket, Key, Body)
    alt Custom endpoint set
        S3Client->>Storage: PUT {endpoint}/{bucket}/{key} (path-style)
    else AWS S3
        S3Client->>Storage: PUT https://{bucket}.s3.{region}.amazonaws.com/{key} (virtual-hosted)
    end
    Storage-->>S3Client: 200 OK
    S3Client-->>S3StorageAdapter: success
    alt Custom endpoint set
        S3StorageAdapter-->>App: url = {endpoint}/{bucket}/{path}
    else AWS S3
        S3StorageAdapter-->>App: url = https://{bucket}.s3.{region}.amazonaws.com/{path}
    end
Loading

Reviews (1): Last reviewed commit: "fix: allow custom S3 enpoint via ENV var..." | Re-trigger Greptile

Comment on lines +80 to +81
const baseURL = this.endpoint ? `${this.endpoint}/${this.bucket}` :
`https://${this.bucket}.s3.${this.region}.amazonaws.com`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Trailing slash in endpoint URL

If AWS_ENDPOINT_URL is set with a trailing slash (e.g. https://minio.example.com/), the constructed object URL becomes https://minio.example.com//bucket/path, which will produce broken object links. Consider stripping the trailing slash on construction.

Suggested change
const baseURL = this.endpoint ? `${this.endpoint}/${this.bucket}` :
`https://${this.bucket}.s3.${this.region}.amazonaws.com`;
const baseURL = this.endpoint ? `${this.endpoint.replace(/\/$/, '')}/${this.bucket}` :
`https://${this.bucket}.s3.${this.region}.amazonaws.com`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant