1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct NestForgeWebConfig {
5 pub app_name: String,
6 pub app_dir: String,
7 pub backend_dir: String,
8 pub port: u16,
9 pub http_port: u16,
10 pub host: String,
11}
12
13impl Default for NestForgeWebConfig {
14 fn default() -> Self {
15 Self {
16 app_name: std::env::var("APP_NAME").unwrap_or_else(|_| "nestforge-app".to_string()),
17 app_dir: std::env::var("APP_DIR").unwrap_or_else(|_| "src/app".to_string()),
18 backend_dir: std::env::var("BACKEND_DIR").unwrap_or_else(|_| "src/backend".to_string()),
19 port: std::env::var("PORT")
20 .unwrap_or_else(|_| "3000".to_string())
21 .parse()
22 .unwrap_or(3000),
23 http_port: std::env::var("HTTP_PORT")
24 .unwrap_or_else(|_| "3001".to_string())
25 .parse()
26 .unwrap_or(3001),
27 host: std::env::var("HOST").unwrap_or_else(|_| "127.0.0.1".to_string()),
28 }
29 }
30}
31
32impl NestForgeWebConfig {
33 pub fn from_env() -> Self {
34 Self::default()
35 }
36
37 pub fn with_port(mut self, port: u16) -> Self {
38 self.port = port;
39 self
40 }
41
42 pub fn with_host(mut self, host: &str) -> Self {
43 self.host = host.to_string();
44 self
45 }
46}