nodes/packages/node_registry_server/src/main.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

2024-03-01 18:23:40 +01:00
use node_registry_rust::NodeRegistryCore;
use tide::Request;
#[async_std::main]
async fn main() -> tide::Result<()> {
let mut app = tide::new();
app.at("/").get(index);
app.at("/nodes/:author/:namespace/:node_id").get(get_node);
app.listen("0.0.0.0:8080").await?;
Ok(())
}
async fn get_node(req: Request<()>) -> tide::Result {
let author = req.param("author")?;
let namespace = req.param("namespace")?;
let node_id = req.param("node_id")?;
let node_registry = NodeRegistryCore::new("../../target/wasm32-unknown-unknown/release");
if node_id.ends_with(".json") {
2024-03-05 18:19:29 +01:00
let res =
node_registry.get_node_definition(author, namespace, &node_id.replace(".json", ""));
match res {
Ok(res) => Ok(format!("Hello {}", res).into()),
Err(er) => Ok(format!("Err: {}", er).into()),
}
2024-03-01 18:23:40 +01:00
} else {
let res = node_registry.get_node(author, namespace, node_id);
match res {
Ok(res) => Ok(format!("Hello {}", res.len()).into()),
Err(er) => Ok(format!("Err: {}", er).into()),
}
}
}
async fn index(_req: Request<()>) -> tide::Result {
Ok(format!("Hello {}", "World").into())
}