aboutsummaryrefslogtreecommitdiff
path: root/apps/servers/octopus/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/servers/octopus/src/main.rs')
-rw-r--r--apps/servers/octopus/src/main.rs42
1 files changed, 34 insertions, 8 deletions
diff --git a/apps/servers/octopus/src/main.rs b/apps/servers/octopus/src/main.rs
index 8ed6445dd4a8..c8660bb92218 100644
--- a/apps/servers/octopus/src/main.rs
+++ b/apps/servers/octopus/src/main.rs
@@ -1,26 +1,52 @@
-//mod git;
-mod pages;
-mod repo;
-mod templ_data;
+//! Octopus git monorepo explorer
+//!
+//! This file is the entry-point to the octopus server (previously
+//! called `webgit` - some mentions to this name are still in the
+//! code).
+//!
+//! Because of the way that the libgit2 rust abstraction handles
+//! state, we can't embed a handle to the repository into the
+//! application app state; instead each endpoint (meaning route) will
+//! load and index the repository itself. Because all operations in
+//! supergit are lazy this does not add too much overhead. If there
+//! are operations that take too long, we can start building an
+//! explicit cache for them.
-mod project;
+#[macro_use]
+extern crate log;
+
+pub(crate) mod git;
+pub(crate) mod pages;
+pub(crate) mod project;
+pub(crate) mod repo;
+pub(crate) mod state;
+pub(crate) mod templ_data;
use actix_files as fs;
-use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
+use actix_web::{web, App, HttpServer};
use std::io;
use std::path::PathBuf;
#[actix_rt::main]
async fn main() -> io::Result<()> {
- std::env::set_var("RUST_LOG", "actix_server=info,octopus=debug");
+ std::env::set_var("RUST_LOG", "actix_server=info,webgit=trace");
env_logger::init();
let root = PathBuf::new();
+ // Check that we know where the repo is.
+ if std::env::var("OCTOPUS_REPOSITORY").is_err() {
+ error!("Failed to determine repository path! Please set the `OCTOPUS_REPOSITORY` env variable!");
+ std::process::exit(2);
+ }
+
+ // Start a new server with a few basic routes
HttpServer::new(move || {
App::new()
.service(fs::Files::new("/static", root.join("static")))
.service(web::resource("/").route(web::get().to(pages::overview)))
- .service(web::resource("/tree").route(web::get().to(pages::files)))
+
+ // Match on tree/* where paths can be arbitrarily recursive
+ .service(web::resource("/tree/{path:[^{}]*}").route(web::get().to(pages::files)))
.default_service(web::resource("").route(web::get().to(pages::p404)))
})
.bind("127.0.0.1:8080")?