make backend more configuratble

This commit is contained in:
cupcakearmy 2022-07-19 16:29:39 +02:00
parent c3bc32bb2b
commit e303b5ed45
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F
5 changed files with 15 additions and 6 deletions

2
backend/Cargo.lock generated
View File

@ -424,7 +424,7 @@ dependencies = [
[[package]]
name = "cryptgeon"
version = "2.0.1"
version = "2.0.2"
dependencies = [
"actix-files",
"actix-web",

View File

@ -1,6 +1,6 @@
[package]
name = "cryptgeon"
version = "2.0.1"
version = "2.0.2"
authors = ["cupcakearmy <hi@nicco.io>"]
edition = "2021"

View File

@ -1,14 +1,17 @@
use actix_files::{Files, NamedFile};
use actix_web::{web, Result};
use crate::config;
pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service(
Files::new("/", "./frontend/build")
Files::new("/", config::FRONTEND_PATH.to_string())
.index_file("index.html")
.use_etag(true),
);
}
pub async fn index() -> Result<NamedFile> {
Ok(NamedFile::open("./frontend/build/index.html")?)
let index = format!("{}{}", config::FRONTEND_PATH.to_string(), "/index.html");
Ok(NamedFile::open(index)?)
}

View File

@ -1,10 +1,16 @@
use byte_unit::Byte;
// General
// Internal
lazy_static! {
pub static ref VERSION: String = option_env!("CARGO_PKG_VERSION")
.unwrap_or("Unknown")
.to_string();
pub static ref FRONTEND_PATH: String = option_env!("FRONTEND_PATH")
.unwrap_or("../frontend/build")
.to_string();
pub static ref LISTEN_ADDR: String = option_env!("LISTEN_ADDR")
.unwrap_or("0.0.0.0:5000")
.to_string();
}
// CONFIG

View File

@ -29,7 +29,7 @@ async fn main() -> std::io::Result<()> {
.configure(client::init)
.default_service(web::to(client::index))
})
.bind("0.0.0.0:5000")?
.bind(config::LISTEN_ADDR.to_string())?
.run()
.await;
}