8000 Append port to the base URL if defined when generating public URLs by Melchyore · Pull Request #6 · flydrive-js/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

8000
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

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

Melchyore
Copy link
Contributor
@Melchyore Melchyore commented Oct 16, 2024

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.

There's another problem (that should be solved in another PR: 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!

@Melchyore Melchyore marked this pull request as ready for review October 21, 2024 11:07
@thetutlage thetutlage merged commit 7295c86 into flydrive-js:develop Dec 18, 2024
@thetutlage
Copy link
Collaborator

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

I think this is the way to go. We can safely include the trailing slash if missing.

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.

2 participants
0