feat: serve requests on auto-assigned default deployment hostnames

TODO: serving custom domain requests are not yet implemented
This commit is contained in:
Aravinth Manivannan 2022-11-10 17:36:01 +05:30
parent ed68b4570c
commit 58bb606879
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
1 changed files with 5 additions and 5 deletions

View File

@ -41,19 +41,17 @@ async fn index(req: HttpRequest, ctx: AppCtx) -> ServiceResult<impl Responder> {
host = host.split(':').next().unwrap(); host = host.split(':').next().unwrap();
} }
// serve meta page
if host == ctx.settings.server.domain || host == "localhost" { if host == ctx.settings.server.domain || host == "localhost" {
return Ok(HttpResponse::Ok() return Ok(HttpResponse::Ok()
.content_type(ContentType::html()) .content_type(ContentType::html())
.body("Welcome to Librepages!")); .body("Welcome to Librepages!"));
} }
if host.contains(&ctx.settings.server.domain) { // serve default hostname content
if host.contains(&ctx.settings.page.base_domain) {
let extractor = crate::preview::Preview::new(&ctx); let extractor = crate::preview::Preview::new(&ctx);
if let Some(preview_branch) = extractor.extract(host) { 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 = if ctx.db.hostname_exists(&host).await? { let res = if ctx.db.hostname_exists(&host).await? {
let path = crate::utils::get_website_path(&ctx.settings, &host); let path = crate::utils::get_website_path(&ctx.settings, &host);
let content = let content =
@ -70,9 +68,11 @@ async fn index(req: HttpRequest, ctx: AppCtx) -> ServiceResult<impl Responder> {
} else { } else {
Err(ServiceError::WebsiteNotFound) Err(ServiceError::WebsiteNotFound)
}; };
return res;
} }
} }
// TODO: custom domains.
if ctx.db.hostname_exists(host).await? { if ctx.db.hostname_exists(host).await? {
let path = crate::utils::get_website_path(&ctx.settings, &host); let path = crate::utils::get_website_path(&ctx.settings, &host);
let content = crate::git::read_file(&path, req.uri().path())?; let content = crate::git::read_file(&path, req.uri().path())?;