Skip to content

Commit

Permalink
feat: attempt to do spa handling
Browse files Browse the repository at this point in the history
  • Loading branch information
barrenechea authored and svenrademakers committed May 3, 2024
1 parent 3269f90 commit 2153ed3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ use crate::{
streaming_data_service::StreamingDataService,
};
use actix_files::Files;
use actix_files::NamedFile;
use actix_web::http::KeepAlive;
use actix_web::{
error::ErrorInternalServerError,
http::{self},
web,
web::Data,
App, HttpRequest, HttpResponse, HttpServer,
App, Error as ActixError, HttpRequest, HttpResponse, HttpServer,
};
use anyhow::Context;
use app::{bmc_application::BmcApplication, event_application::run_event_listener};
Expand All @@ -62,6 +64,14 @@ use tracing_subscriber::Layer;

const HTTP_PORT: u16 = 80;

async fn react_index() -> Result<NamedFile, ActixError> {
let config = Config::try_from(config_path())
.map_err(|e| ErrorInternalServerError(format!("Error parsing config file: {}", e)))?;
let www_root = config.www.clone();
NamedFile::open(www_root.join("index.html"))
.map_err(|e| ErrorInternalServerError(e))

Check failure on line 72 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant closure

error: redundant closure --> src/main.rs:72:18 | 72 | .map_err(|e| ErrorInternalServerError(e)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `ErrorInternalServerError` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure = note: `-D clippy::redundant-closure` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]`
}

#[actix_web::main]
async fn main() -> anyhow::Result<()> {
let _logger_lifetime = init_logger();
Expand Down Expand Up @@ -97,6 +107,9 @@ async fn main() -> anyhow::Result<()> {
)
// Serve a static tree of files of the web UI. Must be the last item.
.service(Files::new("/", &config.www).index_file("index.html"))
.default_service(
web::route().to(react_index)
)
})
.bind_openssl((config.host.clone(), config.port), tls)?
.keep_alive(KeepAlive::Os)
Expand Down

0 comments on commit 2153ed3

Please sign in to comment.