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 committed Apr 28, 2024
1 parent fce2d93 commit cfaae9c
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))
}

#[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 cfaae9c

Please sign in to comment.