feat: serve previews
This commit is contained in:
parent
4d136f2407
commit
c51df7daf2
2 changed files with 50 additions and 18 deletions
|
@ -29,6 +29,7 @@ mod errors;
|
|||
mod git;
|
||||
mod meta;
|
||||
mod page;
|
||||
mod preview;
|
||||
mod routes;
|
||||
mod serve;
|
||||
mod settings;
|
||||
|
|
67
src/serve.rs
67
src/serve.rs
|
@ -56,28 +56,59 @@ async fn index(req: HttpRequest, ctx: AppCtx) -> ServiceResult<impl Responder> {
|
|||
}
|
||||
|
||||
if host == ctx.settings.server.domain || host == "localhost" {
|
||||
Ok(HttpResponse::Ok()
|
||||
return Ok(HttpResponse::Ok()
|
||||
.content_type(ContentType::html())
|
||||
.body("Welcome to Librepages!"))
|
||||
} else {
|
||||
match find_page(host, &ctx) {
|
||||
Some(page) => {
|
||||
log::debug!("Page found");
|
||||
let content = crate::git::read_file(&page.path, req.uri().path())?;
|
||||
let mime = if let Some(mime) = content.mime.first_raw() {
|
||||
mime
|
||||
} else {
|
||||
"text/html; charset=utf-8"
|
||||
};
|
||||
.body("Welcome to Librepages!"));
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
//.content_type(ContentType::html())
|
||||
.content_type(mime)
|
||||
.body(content.content.bytes()))
|
||||
}
|
||||
None => Err(ServiceError::WebsiteNotFound),
|
||||
if host.contains(&ctx.settings.server.domain) {
|
||||
let extractor = crate::preview::Preview::new(&ctx);
|
||||
if let Some(preview_branch) = extractor.extract(host) {
|
||||
unimplemented!(
|
||||
"map a local subdomain on settings.server.domain and use it to fetch page"
|
||||
);
|
||||
let res = match find_page(host, &ctx) {
|
||||
Some(page) => {
|
||||
log::debug!("Page found");
|
||||
let content = crate::git::read_preview_file(
|
||||
&page.path,
|
||||
preview_branch,
|
||||
req.uri().path(),
|
||||
)?;
|
||||
let mime = if let Some(mime) = content.mime.first_raw() {
|
||||
mime
|
||||
} else {
|
||||
"text/html; charset=utf-8"
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
//.content_type(ContentType::html())
|
||||
.content_type(mime)
|
||||
.body(content.content.bytes()))
|
||||
}
|
||||
None => Err(ServiceError::WebsiteNotFound),
|
||||
};
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
match find_page(host, &ctx) {
|
||||
Some(page) => {
|
||||
log::debug!("Page found");
|
||||
let content = crate::git::read_file(&page.path, req.uri().path())?;
|
||||
let mime = if let Some(mime) = content.mime.first_raw() {
|
||||
mime
|
||||
} else {
|
||||
"text/html; charset=utf-8"
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
//.content_type(ContentType::html())
|
||||
.content_type(mime)
|
||||
.body(content.content.bytes()))
|
||||
}
|
||||
None => Err(ServiceError::WebsiteNotFound),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
|
|
Loading…
Reference in a new issue