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]] [[package]]
name = "cryptgeon" name = "cryptgeon"
version = "2.0.1" version = "2.0.2"
dependencies = [ dependencies = [
"actix-files", "actix-files",
"actix-web", "actix-web",

View File

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

View File

@ -1,14 +1,17 @@
use actix_files::{Files, NamedFile}; use actix_files::{Files, NamedFile};
use actix_web::{web, Result}; use actix_web::{web, Result};
use crate::config;
pub fn init(cfg: &mut web::ServiceConfig) { pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service( cfg.service(
Files::new("/", "./frontend/build") Files::new("/", config::FRONTEND_PATH.to_string())
.index_file("index.html") .index_file("index.html")
.use_etag(true), .use_etag(true),
); );
} }
pub async fn index() -> Result<NamedFile> { 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; use byte_unit::Byte;
// General // Internal
lazy_static! { lazy_static! {
pub static ref VERSION: String = option_env!("CARGO_PKG_VERSION") pub static ref VERSION: String = option_env!("CARGO_PKG_VERSION")
.unwrap_or("Unknown") .unwrap_or("Unknown")
.to_string(); .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 // CONFIG

View File

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