ngrok
This library can be used to create an ngrok tunnel for local development that forwards HTTP requests to a localhost endpoint.
When compiled to the cloud, this resource is a no-op.
Prerequisites
- winglang.
- An ngrok account.
NGROK_AUTHTOKEN
should include the auth token for your ngrok user.
Installation
npm i @winglibs/ngrok
Usage
Let's forward all requests that are sent to eladb.ngrok.dev
to our cloud.Api
.
bring ngrok;
let api = new cloud.Api();
api.get("/", inflight () => {
return {
status: 200,
body: "hello ngrok!"
};
});
let t = new ngrok.Tunnel(api.url,
domain: "eladb.ngrok.dev",
// optional callback
onConnect: inflight (url: str) => {
log("connected to {url}");
},
);
// you can add listeners
t.onConnect(inflight (url) => {
log("url: {url}");
});
new cloud.Function(inflight () => {
log("tunnel connected to {t.url}");
});
Once a tunnel is initialized, if an onConnect
callback is set, it will be called with the external
URL of the tunnel. You can use this hook, for example, to update a webhook URL with a dynamic ngrok
endpoint.
Maintainers
License
This library is licensed under the MIT License.
API Reference
Table of Contents
- Classes
- Interfaces
- Structs
Tunnel (preflight class)
No description
Constructor
new(url: str, props: NgrokProps?): Tunnel
Properties
Name | Type | Description |
---|---|---|
url | str | No description |
Methods
Signature | Description |
---|---|
onConnect(handler: inflight (str): void): void | No description |
OnConnectHandler (interface)
No description
Properties
No properties
Methods
Signature | Description |
---|---|
inflight handle(url: str): void | No description |
NgrokProps (struct)
No description
Properties
Name | Type | Description |
---|---|---|
domain | str? | No description |
onConnect | (inflight (str): void)? | No description |