This repository has been archived by the owner on Apr 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serve web client if configuration option is present
- Loading branch information
silverpill
committed
Dec 24, 2022
1 parent
b14338d
commit dea6bca
Showing
7 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ mod monero; | |
pub mod nodeinfo; | ||
mod utils; | ||
pub mod webfinger; | ||
mod web_client; | ||
pub mod web_client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod urls; | ||
pub mod views; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::path::Path; | ||
|
||
use actix_files::{Files, NamedFile}; | ||
use actix_web::{ | ||
dev::{fn_service, ServiceRequest, ServiceResponse}, | ||
web::Data, | ||
}; | ||
|
||
use crate::config::Config; | ||
|
||
pub fn web_client_service(web_client_dir: &Path) -> Files { | ||
Files::new("/", web_client_dir) | ||
.index_file("index.html") | ||
.prefer_utf8(true) | ||
.default_handler(fn_service(|service_request: ServiceRequest| { | ||
// Workaround for https://github.com/actix/actix-web/issues/2617 | ||
let (request, _) = service_request.into_parts(); | ||
let index_path = request.app_data::<Data<Config>>() | ||
.expect("app data should contain config") | ||
.web_client_dir.as_ref() | ||
.expect("web_client_dir should be present in config") | ||
.join("index.html"); | ||
async { | ||
let index_file = NamedFile::open_async(index_path).await?; | ||
let response = index_file.into_response(&request); | ||
Ok(ServiceResponse::new(request, response)) | ||
} | ||
})) | ||
} |