-
Notifications
You must be signed in to change notification settings - Fork 1
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
Make reproxy workable on Bun and Cloudfalre Workers #67
Conversation
Other JS runtime will outputs an error of undeclared.
Export app as default for other runtimes.
WalkthroughThe pull request introduces updates to the Changes
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #67 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 109 110 +1
Branches 6 6
=========================================
+ Hits 109 110 +1 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (6)
src/server.ts (2)
59-59
: Good addition for Deno support. Consider Bun and Cloudflare Workers implementations.The conditional Deno.serve() call is a good step towards multi-platform support. It allows the application to run in a Deno environment while remaining compatible with other platforms.
To fully meet the PR objectives, consider adding similar conditional checks for Bun and Cloudflare Workers environments. Here's a suggestion:
if (typeof Deno !== "undefined") { Deno.serve(app.fetch); } else if (typeof Bun !== "undefined") { Bun.serve({ fetch: app.fetch }); } else if (typeof globalThis.addEventListener !== "undefined") { // Cloudflare Workers environment addEventListener("fetch", (event) => { event.respondWith(app.fetch(event.request)); }); }This structure allows the application to adapt to different environments, fulfilling the goal of making it workable on Bun and Cloudflare Workers as well as Deno.
Line range hint
24-59
: Overall good changes, but more work needed for full multi-platform supportThe changes in this PR are a step in the right direction:
- The default export of
app
simplifies usage.- The conditional Deno.serve() call adds support for Deno environments.
However, to fully meet the PR objectives of making the project workable on Bun and Cloudflare Workers:
- Implement conditional checks and appropriate serve methods for Bun and Cloudflare Workers environments.
- Consider adding tests to verify the behavior in different environments.
- Update the project documentation to reflect these new capabilities and any specific setup required for each platform.
These additional steps will ensure the project meets its goal of being versatile across Deno, Bun, and Cloudflare Workers environments.
README.md (4)
49-55
: LGTM! Consider explaining the permissions.The Deno setup instructions are clear and concise. However, it might be beneficial to explain why the
-A
flag (granting all permissions) is necessary, or if a more restrictive set of permissions could be used.Consider adding a brief note about the permissions, for example:
> Note: The `-A` flag grants all permissions. For production use, you may want to restrict permissions based on your specific needs.
57-70
: LGTM! Consider clarifying the import statement's purpose.The Bun setup instructions are clear and provide a good step-by-step guide. However, the purpose of the side-effect import might not be immediately clear to all users.
Consider adding a brief explanation of why the import statement is necessary, for example:
1. Add this code to the `index.ts` to initialize the Reproxy application: ```ts // This import initializes the Reproxy application import "@5ouma/reproxy";--- `91-108`: **LGTM! Consider adding more details about `wrangler.toml` setup.** The Cloudflare Workers deployment instructions are clear and cover the main steps. However, there are a few points that could be improved for clarity and completeness. Consider the following improvements: 1. Provide more details on setting up `wrangler.toml`, perhaps with a basic example or a link to Cloudflare's documentation. 2. Clarify that users need to have a Cloudflare account and have set up Wrangler CLI. 3. Mention that the environment variables should be set in the Cloudflare dashboard or through Wrangler. For example: ```markdown 1. Set up the `wrangler.toml` file in your project root: ```toml name = "reproxy" main = "index.ts" compatibility_date = "2023-01-01" [vars] REPOSITORY_OWNER = "your_github_username" REPOSITORY_NAME = "your_repo_name" REPOSITORY_PATH = "path/to/file"
Note: Make sure you have a Cloudflare account and have set up the Wrangler CLI. For more details, see Cloudflare's documentation.
Add this code to the
index.ts
:import "@5ouma/reproxy";Deploy with these commands:
npx jsr add @5ouma/reproxy npx wrangler deploy index.tsNote: Ensure that you've set the required environment variables in the Cloudflare dashboard or through Wrangler for production deployments.
--- `89-109`: **Consider updating the Environment Variables section.** While the Environment Variables section provides clear information about the required variables, it doesn't reflect the new deployment options (Bun and Cloudflare Workers) that were added in the setup instructions. Consider updating this section to include information on how to set these variables for each deployment option. For example: ```markdown ## 🌍 Environment Variables | Name | Required | | :----------------: | :------: | | `REPOSITORY_OWNER` | yes | | `REPOSITORY_NAME` | yes | | `REPOSITORY_PATH` | yes | | [`GITHUB_TOKEN`] | no | > [!NOTE] > You need to add [`GITHUB_TOKEN`] if you want to: > > - Access the file in the private repository > - Avoid the API usage limit [`GITHUB_TOKEN`]: https://github.com/settings/tokens/new?scopes=repo ### Setting Environment Variables - For local development: Use a `.env` file as described in the Setup section. - For Deno Deploy: Set these in your project settings on the Deno Deploy dashboard. - For Cloudflare Workers: Set these in your `wrangler.toml` file or in the Cloudflare dashboard.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- README.md (2 hunks)
- src/server.test.ts (1 hunks)
- src/server.ts (2 hunks)
🔇 Additional comments (4)
src/server.test.ts (2)
Line range hint
11-62
: Verify test coverage and functionality.The tests appear to be unchanged and should still be valid after the import modification. However, it's important to ensure that:
- The test coverage is still comprehensive.
- All tests pass with the new default export of
app
.To verify the test coverage and functionality, please run the following commands:
#!/bin/bash # Description: Run tests and check coverage # Test: Run the tests. Expect: All tests to pass. deno test src/server.test.ts # Test: Check test coverage. Expect: High coverage percentage. deno test --coverage=cov_profile src/server.test.ts deno coverage cov_profileIf all tests pass and the coverage is satisfactory, no further changes are needed. If any issues are found, please address them accordingly.
4-4
: LGTM! Verify consistency across the codebase.The change from a named import to a default import for
app
aligns with the PR objective of exportingapp
as the default export. This modification enhances the flexibility of the code for use in different environments.To ensure consistency, let's verify that this change has been applied uniformly across the codebase:
✅ Verification successful
Let's correct the previous shell scripts to properly verify the import statements:
Import Change Verified
The switch from a named import to a default import for
app
has been successfully applied consistently across the codebase. No remaining named imports were found.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining named imports of 'app' from "./server.ts" # Test: Search for named imports of 'app'. Expect: No results. rg --type typescript 'import \{ .*app.* \} from "./server.ts"' # Test: Search for default imports of 'app'. Expect: Results showing the new import style. rg --type typescript 'import app from "./server.ts"'Length of output: 526
Script:
#!/bin/bash # Description: Check for any remaining named imports of 'app' from "./server.ts" # Test: Search for named imports of 'app'. Expect: No results. rg --type=ts 'import \{[^}]*\bapp\b[^}]*\} from "\./server\.ts"' # Test: Search for default imports of 'app'. Expect: Results showing the new import style. rg --type=ts '^import app from "\./server\.ts"'Length of output: 166
src/server.ts (1)
24-25
: LGTM! Consider verifying import statements.The change to export
app
as the default export simplifies usage and aligns with the PR objective. This modification enhances the module's flexibility.To ensure this change doesn't break existing imports, please run the following script:
If the script returns any results, those files may need to be updated to use the new default import syntax.
✅ Verification successful
All import statements are correctly updated and compatible.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any imports of 'app' that might need updating # Test: Search for imports of 'app' from this file rg --type typescript "import.*app.*from.*server" -g '!src/server.ts'Length of output: 105
Script:
#!/bin/bash # Description: Check for any imports of 'app' that might need updating # Test: Search for imports of 'app' from this file rg --type ts "import.*app.*from.*server" -g '!src/server.ts'Length of output: 112
README.md (1)
Line range hint
1-109
: Overall, the README updates align well with the PR objectives.The additions to the README.md file successfully address the PR's goal of making reproxy workable on Bun and Cloudflare Workers. The new setup instructions for different runtimes and deployment options significantly enhance the documentation, making it more accessible to a wider range of users.
While there are some minor suggestions for improvement in the previous comments, the overall changes are positive and contribute to the project's usability across different platforms.
close #
🔄 Type of the Change
✏️ Description
Deno.serve()
when run on Denoapp
as default