FluffySpoon.Ngrok 1.151.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package FluffySpoon.Ngrok --version 1.151.0
                    
NuGet\Install-Package FluffySpoon.Ngrok -Version 1.151.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FluffySpoon.Ngrok" Version="1.151.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluffySpoon.Ngrok" Version="1.151.0" />
                    
Directory.Packages.props
<PackageReference Include="FluffySpoon.Ngrok" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FluffySpoon.Ngrok --version 1.151.0
                    
#r "nuget: FluffySpoon.Ngrok, 1.151.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FluffySpoon.Ngrok@1.151.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FluffySpoon.Ngrok&version=1.151.0
                    
Install as a Cake Addin
#tool nuget:?package=FluffySpoon.Ngrok&version=1.151.0
                    
Install as a Cake Tool

FluffySpoon.Ngrok

A NuGet package used to start Ngrok programmatically and fetch the tunnel URL. Useful to enable for local development when a public URL is needed.

Examples

Console application

Add AddNgrok to your service registration

var services = new ServiceCollection();
services.AddNgrok();

var serviceProvider = services.BuildServiceProvider();
var ngrokService = serviceProvider.GetService<INgrokService>();

//this downloads the Ngrok executable and starts it in the background.
await ngrokService.InitializeAsync();

//this opens a tunnel for the given URL
var tunnel = await ngrokService.StartAsync(new Uri("http://localhost:80"));
Console.WriteLine("Ngrok tunnel URL for localhost:80 is: " + tunnel.PublicUrl);

//the active tunnel can also be accessed using ngrokService.ActiveTunnel.

//we may stop the tunnel as well.
await ngrokService.StopAsync();

ASP .NET Core application

For this example, the FluffySpoon.Ngrok.AspNet package has to be installed.

var builder = WebApplication.CreateBuilder();

//this is the line that is needed to automatically start the tunnel with your ASP .NET Core application.
builder.Services.AddNgrokHostedService();

builder.Services.AddControllersWithViews();

var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

await app.RunAsync();

Getting the tunnel URL

To get the tunnel URL in an ASP .NET Core application, you can just inject a INgrokService into your controller or class.

public class HomeController : Controller
{
    private readonly INgrokService _ngrokService;

    public HomeController(INgrokService ngrokService)
    {
        _ngrokService = ngrokService;
    }

    public IActionResult Index()
    {
        var tunnel = await _ngrokService.ActiveTunnel;
        Console.WriteLine("Tunnel URL is: " + tunnel.PublicUrl);
        
        return View();
    }
}

Waiting for the tunnel to be ready

On the INgrokService, you can call a method to wait for the tunnel to be ready.

await ngrokService.WaitUntilReadyAsync();

Registering lifetime hooks

These are useful if you want to debug things like webhooks etc locally.

class SomeLifetimeHook : INgrokLifetimeHook
{    
    public Task OnCreatedAsync(TunnelResponse tunnel, CancellationToken cancellationToken)
    {
        //TODO: do something when a tunnel has been created. for instance, here you could register a webhook for "tunnel.PublicUrl".
        return Task.CompletedTask;
    }

    public Task OnDestroyedAsync(TunnelResponse tunnel, CancellationToken cancellationToken)
    {
        //TODO: do something when a tunnel has been destroyed. for instance, here you could unregister a webhook for "tunnel.PublicUrl".
        return Task.CompletedTask;
    }
}

And you can register a lifetime hook as such:

services.AddNgrokLifetimeHook<MyHook>();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FluffySpoon.Ngrok:

Package Downloads
FluffySpoon.Ngrok.AspNet

Integration of Ngrok with the AspNetCore pipeline. Tools to automatically create ngrok tunnels on application startup

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on FluffySpoon.Ngrok:

Repository Stars
hsakoh/switchbot-mqtt
SwitchBot MQTT Home Assistant add-on
Version Downloads Last Updated
1.164.0 13,695 1/13/2024
1.163.0 2,050 3/4/2023
1.162.0 405 3/4/2023
1.160.0 332 3/4/2023
1.159.0 337 3/4/2023
1.157.0 477 2/25/2023
1.156.0 441 2/25/2023
1.155.0 494 2/24/2023
1.154.0 347 2/24/2023
1.153.0 340 2/24/2023
1.152.0 346 2/24/2023
1.151.0 664 2/22/2023
1.148.0 350 2/22/2023
1.147.0 349 2/22/2023
1.146.0 335 2/21/2023
1.133.0 367 2/21/2023
1.132.0 376 2/21/2023
1.131.0 370 2/21/2023
1.128.0 376 2/20/2023
1.119.0 776 1/22/2023
1.118.0 743 11/20/2022
1.117.0 428 11/20/2022
1.116.0 579 11/8/2022
1.115.0 1,940 3/12/2022
1.114.0 545 3/12/2022
1.112.0 3,256 3/12/2022