You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.8 KiB
55 lines
1.8 KiB
//! 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.
|
|
|
|
#[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, 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,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)))
|
|
|
|
// 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")?
|
|
.run()
|
|
.await
|
|
}
|
|
|