about summary refs log tree commit diff
path: root/indexer
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2022-11-05 01:00:05 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2022-11-05 17:24:54 +0100
commitf2b946f1af005f6be15efd67f5b1508a30fa0c92 (patch)
tree5a5463bb11aaa7ac284e1c6c514832d53767a789 /indexer
parentIndexer: Actix: Use the same service handler with multiple routes (diff)
downloadOSSE-f2b946f1af005f6be15efd67f5b1508a30fa0c92.tar.gz
OSSE-f2b946f1af005f6be15efd67f5b1508a30fa0c92.tar.bz2
OSSE-f2b946f1af005f6be15efd67f5b1508a30fa0c92.zip
Indexer+Frontend: Integrate with actix
Diffstat (limited to 'indexer')
-rw-r--r--indexer/Cargo.toml1
-rw-r--r--indexer/src/main.rs15
2 files changed, 13 insertions, 3 deletions
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>,