-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add support s3 custom domain #2014
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for custom domain endpoints for S3 private buckets, allowing URLs to be rewritten to use a configured custom domain instead of the default S3 endpoint.
- Introduces a new configuration parameter
privateBucketEndpointfor custom domain support - Implements URL replacement logic to swap S3 endpoints with custom domains
- Updates internal operations to consistently use
s3ClientPrivateNetworkinstead ofs3Client
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| apps/nestjs-backend/src/features/attachments/plugins/s3.ts | Adds replaceBucketEndpoint method, applies URL replacement to presigned URLs, switches internal S3 operations to use private network client, adds debug logging |
| apps/nestjs-backend/src/configs/storage.ts | Adds privateBucketEndpoint configuration parameter from environment variable |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| private replaceBucketEndpoint(url: string, bucket: string): string { | ||
| const { privateBucketEndpoint, privateBucket } = this.config; | ||
| if (privateBucketEndpoint && bucket === privateBucket) { | ||
| const resUrl = new URL(url, privateBucketEndpoint); |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second parameter of URL constructor is intended to be a base URL for relative paths. However, url is already an absolute URL from getSignedUrl. This will cause the privateBucketEndpoint to be ignored. Remove the second parameter and create two separate URL objects.
| const resUrl = new URL(url, privateBucketEndpoint); | |
| const resUrl = new URL(url); |
| }; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| } catch (e: any) { | ||
| console.log('S3 presigned error', e); |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug console.log should be replaced with proper logging using a logger service. Console logs are not appropriate for production code and don't support log levels or structured logging.
| }); | ||
| return this.replaceBucketEndpoint(res, bucket); | ||
| } | ||
| uploadFileWidthPath( |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'Width' to 'With' in method name.
| filePath: string, | ||
| metadata: Record<string, unknown> | ||
| ) { | ||
| console.log('start uploadFileWidthPath', bucket, path, filePath, metadata); |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug console.log should be replaced with proper logging using a logger service. Console logs are not appropriate for production code and don't support log levels or structured logging.
| .finally(() => { | ||
| readStream.removeAllListeners(); | ||
| readStream.destroy(); | ||
| console.log('end uploadFileWidthPath'); |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug console.log should be replaced with proper logging using a logger service. Console logs are not appropriate for production code and don't support log levels or structured logging.
| publicUrl: process.env.BACKEND_STORAGE_PUBLIC_URL, | ||
| publicBucket: process.env.BACKEND_STORAGE_PUBLIC_BUCKET || 'public', | ||
| privateBucket: process.env.BACKEND_STORAGE_PRIVATE_BUCKET || 'private', | ||
| privateBucketEndpoint: process.env.BACKEND_STORAGE_PRIVATE_BUCKET_ENDPOINT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add example and doc for this .env
Pull Request Test Coverage Report for Build 18744952466Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
🧹 Preview Environment Cleanup
|
* feat: add support s3 custom domain * chore: remove log code and env example * refactor: use AWS official method for S3 custom domain * feat: support aliyun oss * feat: debug s3 sockets connection count * chore: safe isNaN
No description provided.