Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant updates to the
cloudflaredlibrary, including the addition of new classes for handling tunnel events, updates to example files, and modifications to the test suite. The most important changes are the introduction of theTunnelclass with enhanced event handling capabilities, updates to the example files to utilize the newTunnelclass, and modifications to the test suite to accommodate these changes.Major Updates to Tunnel Handling:
src/tunnel.ts: Introduced theTunnelclass, which extendsEventEmitterand includes methods for handling tunnel events such asurl,connected,disconnected,stdout,stderr,error, andexit. Added static methodsquickandwithTokenfor creating tunnels with or without a Cloudflare account.Example Files Updates:
examples/tunnel.js,examples/tunnel.mjs: Updated to use the newTunnelclass instead of the previoustunnelfunction. This change simplifies the code and leverages the new event handling capabilities of theTunnelclass. [1] [2]examples/events.mjs: Added a new example file demonstrating how to use theTunnelclass and handle various events such asurl,connected,disconnected,stdout,stderr,exit, anderror.Test Suite Modifications:
src/_tests/index.test.ts: Updated the test suite to use the newTunnelclass instead of the previoustunnelfunction. Added a timeout configuration to thedescribeblocks to ensure tests complete within a reasonable time frame. [1] [2] [3]Additional Enhancements:
src/handler.ts: Added new classesConnectionHandler,TryCloudflareHandler, andConfigHandlerto handle specific tunnel events and configurations. These classes are used internally by theTunnelclass to process output and emit relevant events.src/lib.ts: Updated exports to include the newTunnelclass and related handlers, ensuring they are available for use in other parts of the application.Documentation Updates:
README.md: Updated the example code to use the newTunnelclass, demonstrating its usage and event handling capabilities. [1] [2]These changes collectively improve the flexibility and functionality of the
cloudflaredlibrary, making it easier to create and manage tunnels with enhanced event handling capabilities.