Skip to content

Conversation

@Murderlon
Copy link
Member

Closes #746

@Murderlon Murderlon self-assigned this May 6, 2025
@changeset-bot
Copy link

changeset-bot bot commented May 6, 2025

🦋 Changeset detected

Latest commit: 1140361

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tus/server Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented May 6, 2025

"""

Walkthrough

The changes introduce a new exposedHeaders option to the server configuration, allowing users to specify additional headers for the Access-Control-Expose-Headers CORS response. Documentation and type definitions are updated, the server logic is modified to concatenate these custom headers, and a new test ensures correct behavior.

Changes

Files/Paths Change Summary
packages/server/README.md Added documentation for the new options.exposedHeaders server option.
packages/server/src/types.ts Extended ServerOptions type with an optional exposedHeaders array property.
packages/server/src/server.ts Updated CORS logic to append custom exposedHeaders to Access-Control-Expose-Headers response header.
packages/server/src/test/Server.test.ts Added a test case verifying that custom exposed headers are correctly included in the CORS response.

Assessment against linked issues

Objective Addressed Explanation
Allow defining custom exposed headers for CORS (Access-Control-Expose-Headers) (#746)
Update type definitions and documentation for the new option (#746)
Add tests to verify custom exposed headers in CORS responses (#746)
"""

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/server/src/server.ts (1)

203-206: Consider handling non-array values more explicitly.

The implementation works but could be more robust against unexpected runtime values. While TypeScript ensures type safety at compile time, consider a more defensive approach for runtime safety.

-  headers.set(
-    'Access-Control-Expose-Headers',
-    [...HEADERS, this.options.exposedHeaders ?? []].join(', ')
-  )
+  headers.set(
+    'Access-Control-Expose-Headers',
+    HEADERS.concat(Array.isArray(this.options.exposedHeaders) ? this.options.exposedHeaders : []).join(', ')
+  )

This change ensures that even if exposedHeaders is somehow not an array at runtime, the code won't throw an error.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64cb30f and 04baa77.

📒 Files selected for processing (4)
  • packages/server/README.md (1 hunks)
  • packages/server/src/server.ts (2 hunks)
  • packages/server/src/test/Server.test.ts (1 hunks)
  • packages/server/src/types.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/server/src/server.ts (1)
packages/utils/src/constants.ts (1)
  • HEADERS (3-21)
🔇 Additional comments (4)
packages/server/src/types.ts (1)

34-37: LGTM! Good addition of the exposedHeaders option.

The type definition and documentation for the new exposedHeaders option are correctly implemented, following the same pattern as the existing allowedHeaders option. This is a useful feature for users who need to expose additional custom headers in CORS responses.

packages/server/README.md (1)

101-104: Documentation looks good!

The documentation for the new exposedHeaders option is clear, concise, and follows the same style as the other options. The placement after allowedHeaders is logical and makes it easy for users to discover related features.

packages/server/src/server.ts (1)

7-7: Updated import looks good.

Correctly updated the import to use HEADERS instead of EXPOSED_HEADERS from the @tus/utils package.

packages/server/src/test/Server.test.ts (1)

166-177: Test case looks great!

The test case properly verifies that custom headers are included in the Access-Control-Expose-Headers response header. The structure follows the same pattern as other CORS header tests, and it correctly cleans up by resetting the option after the test.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.changeset/tidy-items-fry.md (1)

5-5: Refine changeset summary style
For consistency with other changesets, consider ending the summary sentence with a period and, if helpful, briefly noting default behavior or usage. For example:
“Introduce exposedHeaders option for custom Access-Control-Expose-Headers.”

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04baa77 and 1140361.

📒 Files selected for processing (1)
  • .changeset/tidy-items-fry.md (1 hunks)
🔇 Additional comments (1)
.changeset/tidy-items-fry.md (1)

1-3: Verify version bump type
The addition of a new exposedHeaders option is indeed a feature enhancement, so marking this as a minor release for @tus/server is correct.

@Murderlon Murderlon merged commit 1768b06 into main May 6, 2025
4 checks passed
@Murderlon Murderlon deleted the exposed-headers branch May 6, 2025 11:31
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.

It should be possible to define exposed headers for CORS

1 participant