43个版本

0.14.0-pre.142024年7月22日
0.14.0-pre.122024年3月11日
0.14.0-pre.92023年11月27日
0.12.4 2023年6月21日
0.5.0 2020年11月23日

网络编程中排名第157

Download history 1027/week @ 2024-04-26 1781/week @ 2024-05-03 1470/week @ 2024-05-10 1330/week @ 2024-05-17 1223/week @ 2024-05-24 1519/week @ 2024-05-31 1444/week @ 2024-06-07 1724/week @ 2024-06-14 1903/week @ 2024-06-21 1685/week @ 2024-06-28 1819/week @ 2024-07-05 1889/week @ 2024-07-12 2413/week @ 2024-07-19 2249/week @ 2024-07-26 1501/week @ 2024-08-02 1845/week @ 2024-08-09

每月下载量8,476
用于cargo-doc-ngrok

MIT/Apache

245KB
6K SLoC

ngrok-rust

Crates.io docs.rs MIT licensed Apache-2.0 licensed Continuous integration

API文档(主)

ngrok是一个简化的以API为中心的入口即服务,它为您的应用添加了连接性、安全性和可观测性。

ngrok-rust,我们为将公共互联网地址以安全的入口流量直接添加到您的Rust应用中而设计的本地化和惯用crate。如果您之前使用过ngrok,可以将ngrok-rust视为打包成Rust crate的ngrok代理。

ngrok-rust让开发者在单行语句中即可在互联网上提供服务Rust服务,无需设置IP、NAT、证书、负载均衡器,甚至端口等低级网络原语!使用ngrok-rust的应用程序监听ngrok的全局入口网络中的TCP和HTTP流量。ngrok-rust监听器与hyper服务器兼容,连接实现了tokio的AsyncRead和AsyncWrite特质。这使得它很容易将ngrok-rust添加到任何基于hyper构建的应用程序中,例如流行的axum HTTP框架。

请参阅/ngrok/examples/中的示例用法,或/ngrok/src/online_tests.rs中的测试。

有关使用ngrok API的信息,请参阅ngrok Rust API客户端库

如果您正在寻找代理包装器,请访问这里。有关迁移的建议,请参阅UPGRADING.md

有关更多信息,请务必查看ngrok-rust发布公告

安装

ngrok 添加到您的 [dependencies] 部分 Cargo.toml

...

[dependencies]
ngrok = "0.13"

...

或者,使用 cargo add

$ cargo add ngrok

快速入门

使用 ngrokaxum 创建简单的 HTTP 服务器

Cargo.toml:

[package]
name = "ngrok-axum-example"
version = "0.1.0"
edition = "2021"

[dependencies]
ngrok = { version="0.13", features=["axum"] }
tokio = { version = "1.26", features = ["full"] }
axum = "0.6"
anyhow = "1.0"

src/main.rs:

use std::net::SocketAddr;

use axum::{
    extract::ConnectInfo,
    routing::get,
    Router,
};
use ngrok::prelude::*;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // build our application with a single route
    let app = Router::new().route(
        "/",
        get(
            |ConnectInfo(remote_addr): ConnectInfo<SocketAddr>| async move {
                format!("Hello, {remote_addr:?}!\r\n")
            },
        ),
    );

    let tun = ngrok::Session::builder()
        // Read the token from the NGROK_AUTHTOKEN environment variable
        .authtoken_from_env()
        // Connect the ngrok session
        .connect()
        .await?
        // Start a tunnel with an HTTP edge
        .http_endpoint()
        .listen()
        .await?;

    println!("Tunnel started on URL: {:?}", tun.url());

    // Instead of binding a local port like so:
    // axum::Server::bind(&"0.0.0.0:8000".parse().unwrap())
    // Run it with an ngrok tunnel instead!
    axum::Server::builder(tun)
        .serve(app.into_make_service_with_connect_info::<SocketAddr>())
        .await
        .unwrap();

    Ok(())
}

变更日志

ngrok-rust 的更改记录在 CHANGELOG.md 中。

加入 ngrok 社区

许可

此项目根据您的选择受以下任一许可的约束

贡献

除非您明确声明,否则任何旨在包含在 ngrok 中的贡献,根据 Apache-2.0 许可证的定义,均应按上述方式双许可,不附加任何额外条款或条件。

依赖项

~19–33MB
~623K SLoC