Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append port to the base URL if defined when generating public URLs #6

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Melchyore
Copy link

Hey! 👋

Following a discussion with @thetutlage on Discord and at his request, I created this PR to address an issue with the getUrl() method: if an S3 endpoint includes a port, the port is stripped when generating a public URL, resulting in an incorrect URL.

This PR fixes this behaviour by adding the port only if it's defined.

This PR will be a draft until Virk decides on another question. When cdnUrl is used, if it doesn't have a trailing slash, the pathname will be removed and the bucket used will not be included in the public URL generated by the getUrl() method. The following is an example for the same:

# In .env

S3_ENDPOINT=http://localhost:9000
S3_BUCKET=local
// In config/drive.ts

{
  s3: services.s3({
    cdnUrl: `${env.get('S3_ENDPOINT')}/${env.get('S3_BUCKET')}`,
  }),
}

In this case, using await drive.use().getUrl('foo/bar.png') will result in the following generated URL: http://localhost:9000/foo/bar.png which is wrong. The correct URL should be: http://localhost:9000/local/foo/bar.png.

To address this issue, we can either add a trailing slash automatically to cdnUrl, or let devs do it manually, i.e :

// In config/drive.ts configuration

{
  s3: services.s3({
    cdnUrl: `${env.get('S3_ENDPOINT')}/${env.get('S3_BUCKET')}/`,
    //                                                        ^----- Here
}

I can work on the second issue too, if necessary.

Thank you!

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