MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / run

Function run

cli/src/serve.rs:12–33  ·  view source on GitHub ↗
(dir: PathBuf, port: u16, open: bool)

Source from the content-addressed store, hash-verified

10use tiny_http::{Header, Response, Server};
11
12pub fn run(dir: PathBuf, port: u16, open: bool) -> Result<()> {
13 let server = Server::http(("127.0.0.1", port)).map_err(|e| anyhow!("could not bind port {port}: {e}"))?;
14
15 // Bumped by the watcher; the injected client polls it and reloads on change.
16 let version = Arc::new(AtomicU64::new(0));
17 spawn_watcher(dir.clone(), version.clone());
18
19 crate::ui::serve_banner(port, &dir);
20 if open {
21 let _ = open_url(&format!("http://localhost:{port}"));
22 }
23
24 for req in server.incoming_requests() {
25 let url = req.url().split('?').next().unwrap_or("/").to_string();
26 if url == "/__livereload" {
27 let _ = req.respond(Response::from_string(version.load(Ordering::Relaxed).to_string()));
28 } else {
29 serve_file(req, &dir, &url);
30 }
31 }
32 Ok(())
33}
34
35fn serve_file(req: tiny_http::Request, dir: &Path, url: &str) {
36 let rel = url.trim_start_matches('/');

Callers

nothing calls this directly

Calls 6

spawn_watcherFunction · 0.85
serve_bannerFunction · 0.85
open_urlFunction · 0.85
serve_fileFunction · 0.85
nextMethod · 0.80
loadMethod · 0.80

Tested by

no test coverage detected