nucleus_http/
virtual_host.rs

1use std::path::PathBuf;
2
3use crate::{request::Request, response::Response, routes::Router};
4
5pub struct VirtualHost<S> {
6    hostname: String,
7    root_dir: PathBuf, // root dir for static files, eg. /var/www/default
8    router: Router<S>,
9}
10
11impl<S> VirtualHost<S>
12where
13    S: Clone + Send + Sync + 'static,
14{
15    pub fn new(hostname: &str, _ip: &str, root_dir: &str, router: Router<S>) -> Self {
16        Self {
17            hostname: hostname.to_string(),
18            //ip: ip.to_string(),
19            root_dir: PathBuf::from(root_dir),
20            router,
21        }
22    }
23
24    pub fn hostname(&self) -> &str {
25        &self.hostname
26    }
27
28    pub fn root_dir(&self) -> &PathBuf {
29        &self.root_dir
30    }
31
32    pub async fn route(&self, request: &Request) -> Response {
33        self.router.route(request, &self.root_dir).await
34    }
35}