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

fix: http to https #264

Merged
merged 3 commits into from
Jul 24, 2024
Merged

Conversation

lorenzomigliorero
Copy link
Contributor

@lorenzomigliorero lorenzomigliorero commented Jul 23, 2024

Fix: #253

When a domain is HTTPS, we need to generate two routers, one for the web and one for the webscure entrypoint.
The redirect-to-https middleware needs to stay on the web router, otherwise it is not catched.

There's a bit of conditioning to manage, I summarise here all the cases:

  • when the domain is HTTPS, the web router middlewares must contain only the redirect-to-https middleware
  • when the domain is HTTP, the web router middlewares must contain only the custom redirects
  • when the domain is HTTPS, the websecure router must contain only the custom redirects

I wrote a unit test file to test these conditions. More tests can be added to cover other features, like domain deletion and domain update, but it's a stable starting point.

Summary by CodeRabbit

  • New Features

    • Introduced a suite of automated unit tests for router configuration, validating HTTP and HTTPS behavior.
    • Enhanced domain management to support separate router configurations for secure and non-secure traffic.
  • Bug Fixes

    • Improved middleware handling to ensure proper application of redirects and security settings based on router configurations.

@lorenzomigliorero lorenzomigliorero marked this pull request as draft July 23, 2024 18:56
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

This update enhances router configuration testing for both HTTP and HTTPS, ensuring proper middleware application based on domain settings. It also improves domain management functionality, allowing for conditional secure router creation and a more streamlined approach to handling entry points. Overall, these changes strengthen the application's routing logic and maintainability.

Changes

Files Change Summary
__test__/traefik/traefik.test.ts, server/utils/traefik/domain.ts Introduced unit tests for router configurations, focusing on HTTP/HTTPS middleware handling. Enhanced domain management logic to conditionally create secure routers and simplified function signatures and middleware application based on entry points.

Assessment against linked issues

Objective Addressed Explanation
Redirect from HTTP to HTTPS should work (Issue #253)
Ensure middleware logic correctly handles secure and non-secure traffic

Poem

🐇 In the realm of routers, so neat,
With middleware dances, oh what a treat!
From HTTP hops to HTTPS plays,
Our changes will shine in many ways.
So let’s celebrate with a joyful cheer,
For our routing’s now crystal clear! ✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d3397cf and 75bd10c.

Files selected for processing (2)
  • test/traefik/traefik.test.ts (1 hunks)
  • server/utils/traefik/domain.ts (4 hunks)
Additional comments not posted (13)
server/utils/traefik/domain.ts (5)

16-16: LGTM!

The introduction of routerNameSecure for handling secure traffic is clear and straightforward.


22-26: LGTM!

The createRouterConfig function is called with the "web" entry point, aligning with the updated function signature for more granular control.


28-37: LGTM!

The conditional creation and deletion of the secure router based on the domain.https flag enhances flexibility in managing HTTP and HTTPS traffic.


47-55: LGTM!

The deletion of the secure router if it exists ensures proper cleanup of configurations.


Line range hint 71-110:
LGTM!

The updated function signature and refined logic for handling entry points and middlewares improve the maintainability and clarity of the code.

__test__/traefik/traefik.test.ts (8)

83-91: LGTM!

The test correctly verifies that the "redirect-to-https" middleware is not added for an HTTP domain.


93-106: LGTM!

The test correctly verifies that the "redirect-to-https" middleware is not added and the redirect middleware is added for an HTTP domain with a redirect.


108-125: LGTM!

The test correctly verifies that the "redirect-to-https" middleware is not added and multiple redirect middlewares are added for an HTTP domain with multiple redirects.


127-135: LGTM!

The test correctly verifies that the "redirect-to-https" middleware is added for an HTTPS domain.


137-150: LGTM!

The test correctly verifies that the "redirect-to-https" middleware is added and the redirect middleware is not added for an HTTPS domain with a redirect.


152-160: LGTM!

The test correctly verifies that the "redirect-to-https" middleware is not added for a "websecure" entry point on an HTTPS domain.


162-175: LGTM!

The test correctly verifies that the "redirect-to-https" middleware is not added and the redirect middleware is added for a "websecure" entry point on an HTTPS domain with a redirect.


179-187: LGTM!

The test correctly verifies that the correct certificate resolver is set for a "websecure" entry point with a "letsencrypt" certificate type.

@lorenzomigliorero lorenzomigliorero marked this pull request as ready for review July 23, 2024 19:05
@Siumauricio
Copy link
Contributor

Siumauricio commented Jul 24, 2024

Thank you for this work @lorenzomigliorero and the test are really appreciated.

everything seems right, just a few note, when adding a domain you need to first enable https and then select a certificate, I think we should hide the certificate select when we have disable the https, because if we had disable https and select a letsencrypt certificate it will not take any effect in the configuration file, so we should hide to improve the UX, that validation should be apply when creating and updating a domain.

server/utils/traefik/domain.ts Outdated Show resolved Hide resolved
@lorenzomigliorero
Copy link
Contributor Author

@Siumauricio Should we condition the certificate in another PR? This is about solving the http-to-https redirect. I'll open it soon!

Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 75bd10c and 1b7ecd5.

Files selected for processing (2)
  • test/traefik/traefik.test.ts (1 hunks)
  • server/utils/traefik/domain.ts (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • test/traefik/traefik.test.ts
  • server/utils/traefik/domain.ts

@Siumauricio Siumauricio merged commit 083bb7b into Dokploy:canary Jul 24, 2024
1 check passed
@Siumauricio Siumauricio mentioned this pull request Jul 27, 2024
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.

redirect-to-https not working for apps deployed with Nixpacks
2 participants