diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-11-05 01:00:05 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-11-05 17:24:54 +0100 |
commit | f2b946f1af005f6be15efd67f5b1508a30fa0c92 (patch) | |
tree | 5a5463bb11aaa7ac284e1c6c514832d53767a789 | |
parent | Indexer: Actix: Use the same service handler with multiple routes (diff) | |
download | OSSE-f2b946f1af005f6be15efd67f5b1508a30fa0c92.tar.gz OSSE-f2b946f1af005f6be15efd67f5b1508a30fa0c92.tar.bz2 OSSE-f2b946f1af005f6be15efd67f5b1508a30fa0c92.zip |
Indexer+Frontend: Integrate with actix
-rw-r--r-- | Cargo.lock | 52 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | crawler/src/main.rs | 2 | ||||
-rw-r--r-- | frontend/src/main.rs | 4 | ||||
-rw-r--r-- | indexer/Cargo.toml | 1 | ||||
-rw-r--r-- | indexer/src/main.rs | 15 |
6 files changed, 69 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock index 343b3b3..6af29e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,6 +220,57 @@ dependencies = [ ] [[package]] +name = "actix-web-lab" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b11277c9258b28bb2189b10c8910b729384d32afc7839d63568e0931d6a5493e" +dependencies = [ + "actix-files", + "actix-http", + "actix-router", + "actix-service", + "actix-utils", + "actix-web", + "actix-web-lab-derive", + "ahash 0.8.1", + "arc-swap", + "async-trait", + "bytes 1.2.1", + "bytestring", + "csv", + "derive_more", + "digest", + "futures-core", + "futures-util", + "generic-array", + "hmac", + "http", + "itertools", + "local-channel", + "mime", + "once_cell", + "pin-project-lite 0.2.9", + "regex", + "serde", + "serde_html_form", + "serde_json", + "subtle", + "tokio 1.21.2", + "tracing", +] + +[[package]] +name = "actix-web-lab-derive" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44a15d9ddb31a4f41decd22f743a154e519fb326120e8133ef9ea6283335ad2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "adler" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1256,6 +1307,7 @@ version = "0.1.0" dependencies = [ "actix-cors", "actix-web", + "actix-web-lab", "html2text", "kuchiki", "lib", diff --git a/README.md b/README.md index ba9c2bf..aee4671 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Install cargo through your preferred method. ### 2. Run! ``` +$ trunk serve frontend/index.html $ cargo run --bin indexer $ cargo run --bin crawler -$ trunk serve frontend/index.html ``` diff --git a/crawler/src/main.rs b/crawler/src/main.rs index 7e7f397..557ba4e 100644 --- a/crawler/src/main.rs +++ b/crawler/src/main.rs @@ -55,7 +55,7 @@ async fn crawler(http_client: Client, root_urls: Vec<&str>, max_queue_size: usiz //push content to index let indexer_response = match push_crawl_entry_to_indexer( &http_client, - "http://127.0.0.1:4444/resource".to_string(), + "http://127.0.0.1:8080/api/resource".to_string(), url, content, ) diff --git a/frontend/src/main.rs b/frontend/src/main.rs index 6732466..29bdd71 100644 --- a/frontend/src/main.rs +++ b/frontend/src/main.rs @@ -17,10 +17,10 @@ enum Route { fn switch_routes(routes: Route) -> Html { match routes { Route::OSSEHome | Route::OSSEHomeEmptySearch => html! { - <OSSE api_endpoint={"http://127.0.0.1:4444"} initial_search_query={None as Option<String>} /> + <OSSE api_endpoint={"/api"} initial_search_query={None as Option<String>} /> }, Route::OSSESearch { query } => html! { - <OSSE api_endpoint={"http://127.0.0.1:4444"} initial_search_query={Some(query)} /> + <OSSE api_endpoint={"/api"} initial_search_query={Some(query)} /> }, } } diff --git a/indexer/Cargo.toml b/indexer/Cargo.toml index 5aa5184..7b64bb3 100644 --- a/indexer/Cargo.toml +++ b/indexer/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] actix-web = "4.2.1" +actix-web-lab = "0.18.5" actix-cors = "0.6.3" scraper = "0.12.0" html2text = "0.4.3" diff --git a/indexer/src/main.rs b/indexer/src/main.rs index 952af96..7d5a1af 100644 --- a/indexer/src/main.rs +++ b/indexer/src/main.rs @@ -32,7 +32,7 @@ struct AppState { async fn main() -> std::io::Result<()> { println!("Hello, world! Im the indexer!"); - serve_http_endpoint("0.0.0.0", 4444).await + serve_http_endpoint("0.0.0.0", 8080).await } async fn serve_http_endpoint(address: &str, port: u16) -> std::io::Result<()> { @@ -45,7 +45,16 @@ async fn serve_http_endpoint(address: &str, port: u16) -> std::io::Result<()> { .wrap(cors) .app_data(shared_state.clone()) .service(add_resource) - .service(web::resource(["/search", "/search/", "/search/{query}"]).to(search)) + .service( + web::resource(["/api/search", "/api/search/", "/api/search/{query}"]).to(search), + ) + .service( + actix_web_lab::web::spa() + .index_file("./frontend/dist/index.html") + .static_resources_mount("/") + .static_resources_location("./frontend/dist") + .finish(), + ) //TODO: maybe separate gui backend from api? }) .bind((address, port))? .run() @@ -53,7 +62,7 @@ async fn serve_http_endpoint(address: &str, port: u16) -> std::io::Result<()> { } //TODO: sufficiently simmilar word in search (algorithm) -#[post("/resource")] +#[post("/api/resource")] async fn add_resource( data: web::Data<AppState>, resource: web::Json<CrawledResource>, |