aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs31
-rw-r--r--src/pages/mod.rs1
-rw-r--r--src/pages/p404.rs13
-rw-r--r--src/pages/repo/about.rs7
-rw-r--r--src/repo.rs10
5 files changed, 35 insertions, 27 deletions
diff --git a/src/main.rs b/src/main.rs
index c0b0f61..d6a4b36 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,18 +1,23 @@
mod pages;
mod repo;
-fn main() -> std::io::Result<()> {
- // use actix_files as fs;
- // use actix_web::{web, App, HttpServer};
+use actix_files as fs;
+use actix_web::{web, App, HttpServer};
+use std::io;
- // start http server
- // HttpServer::new(move || {
- // App::new()
- // .service(fs::Files::new("/static", "static"))
- // .service(web::resource("/{repo}").route(web::get().to(pages::repo::render)))
- // })
- // .bind("127.0.0.1:8080")?
- // .run()?;
-
- Ok(())
+#[actix_rt::main]
+async fn main() -> io::Result<()> {
+ HttpServer::new(|| {
+ App::new()
+ .service(fs::Files::new("/static", "static"))
+ .service(web::resource("/{repo}").route(web::get().to(pages::repo::about::render)))
+ // default
+ .default_service(
+ // 404 for GET request
+ web::resource("").route(web::get().to(pages::p404::render)),
+ )
+ })
+ .bind("127.0.0.1:8080")?
+ .run()
+ .await
}
diff --git a/src/pages/mod.rs b/src/pages/mod.rs
index 9de9d47..d53561b 100644
--- a/src/pages/mod.rs
+++ b/src/pages/mod.rs
@@ -4,3 +4,4 @@
//! which is exported from the module and then called by the router
pub mod repo;
+pub mod p404;
diff --git a/src/pages/p404.rs b/src/pages/p404.rs
new file mode 100644
index 0000000..6427a19
--- /dev/null
+++ b/src/pages/p404.rs
@@ -0,0 +1,13 @@
+use actix_web::{HttpResponse, Result};
+use askama::Template;
+
+#[derive(Template)]
+#[template(path = "404.html")]
+struct P404;
+
+/// Render a simple 404 page
+pub async fn render() -> Result<HttpResponse> {
+ Ok(HttpResponse::NotFound()
+ .content_type("text/html")
+ .body(P404.render().unwrap()))
+}
diff --git a/src/pages/repo/about.rs b/src/pages/repo/about.rs
index adfa46e..8797edd 100644
--- a/src/pages/repo/about.rs
+++ b/src/pages/repo/about.rs
@@ -1,5 +1,3 @@
-//! The "repository/about" subpage
-
use actix_web::{web, HttpRequest, HttpResponse, Result};
use askama::Template;
@@ -16,7 +14,8 @@ struct Repo<'a> {
num_contributors: usize,
}
-pub fn render(req: HttpRequest, path: web::Path<(String)>) -> Result<HttpResponse> {
+/// Renders the "repository/about" subpage
+pub async fn render(req: HttpRequest, path: web::Path<String>) -> Result<HttpResponse> {
println!("Rendering path: {:#?}", path);
dbg!(req);
@@ -31,6 +30,6 @@ pub fn render(req: HttpRequest, path: web::Path<(String)>) -> Result<HttpRespons
num_contributors: 3,
}
.render()
- .unwrap();
+ .unwrap();
Ok(HttpResponse::Ok().content_type("text/html").body(repo))
}
diff --git a/src/repo.rs b/src/repo.rs
index 3dae808..ca1f889 100644
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -1,16 +1,6 @@
use git2::{Commit, Error, Repository as Backend};
use std::collections::HashSet;
-// /// Represents a repository on disk
-// struct Repository {
-// /// We need to be able to query libgit2 later
-// fs_path: String,
-// /// The project name (last path element)
-// name: String,
-// /// The rope path excluding the name
-// path: Vec<String>,
-// }
-
/// A structure that represents an existing bare repo on disk
pub struct Repository {
inner: Backend,