feat: boxygit add .
This commit is contained in:
parent
ba8d1b9453
commit
a8bc61f40c
15 changed files with 4700 additions and 0 deletions
2615
examples/example-server/Cargo.lock
generated
Normal file
2615
examples/example-server/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
9
examples/example-server/Cargo.toml
Normal file
9
examples/example-server/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "example-server"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.12.22", features = ["json", "blocking"] }
|
||||
rocket = "0.5.1"
|
||||
serde_json = "1.0.141"
|
41
examples/example-server/src/main.rs
Normal file
41
examples/example-server/src/main.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use std::{collections::HashMap, fmt::format};
|
||||
|
||||
use rocket::{build, get, launch, routes};
|
||||
use serde_json::json;
|
||||
|
||||
extern crate rocket;
|
||||
|
||||
const BOXY_ADDRESS: &str = "localhost";
|
||||
const BOXY_PORT: u16 = 8006;
|
||||
|
||||
const CLIENT_NAME: &str = "eu-central-1";
|
||||
const CLIENT_SECRET: &str = "password123";
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> &'static str {
|
||||
"Hello world!"
|
||||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
// This is the example backend client. (The stereo.cat backend for example).
|
||||
let client = reqwest::blocking::Client::new();
|
||||
|
||||
// We define the port of the server running locally and the hostname we want to route to it.
|
||||
let body = json!({
|
||||
"port": 8000,
|
||||
"hostname": "localhost:8005",
|
||||
});
|
||||
|
||||
// Send it to Boxy's API
|
||||
let res = client
|
||||
.post(format!("http://{}:{}/register", BOXY_ADDRESS, BOXY_PORT))
|
||||
.basic_auth(CLIENT_NAME, Some(CLIENT_SECRET))
|
||||
.json(&body)
|
||||
.send()
|
||||
.unwrap();
|
||||
|
||||
println!("{}", res.text().unwrap());
|
||||
|
||||
build().mount("/", routes![index])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue