|
@ -85,14 +85,20 @@ pub fn redir_snippet(target: &str) -> String { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub trait SocketSpec {
|
|
|
pub trait SocketSpec {
|
|
|
fn to_nginx(&self) -> String;
|
|
|
|
|
|
|
|
|
fn to_proxy_pass(&self) -> String;
|
|
|
|
|
|
fn to_uwsgi_pass(&self) -> String;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<T: AsRef<Path>> SocketSpec for T {
|
|
|
impl<T: AsRef<Path>> SocketSpec for T {
|
|
|
#[must_use]
|
|
|
#[must_use]
|
|
|
fn to_nginx(&self) -> String {
|
|
|
|
|
|
|
|
|
fn to_proxy_pass(&self) -> String {
|
|
|
format!("unix:{}:", self.as_ref().to_str().unwrap())
|
|
|
format!("unix:{}:", self.as_ref().to_str().unwrap())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
|
|
fn to_uwsgi_pass(&self) -> String {
|
|
|
|
|
|
format!("unix:{}", self.as_ref().to_str().unwrap())
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
#[derive(Debug)]
|
|
@ -107,7 +113,12 @@ impl LocalTcpSocket { |
|
|
|
|
|
|
|
|
impl SocketSpec for LocalTcpSocket {
|
|
|
impl SocketSpec for LocalTcpSocket {
|
|
|
#[must_use]
|
|
|
#[must_use]
|
|
|
fn to_nginx(&self) -> String {
|
|
|
|
|
|
|
|
|
fn to_proxy_pass(&self) -> String {
|
|
|
|
|
|
format!("localhost:{}", self.0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
|
|
fn to_uwsgi_pass(&self) -> String {
|
|
|
format!("localhost:{}", self.0)
|
|
|
format!("localhost:{}", self.0)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -129,7 +140,28 @@ pub fn proxy_snippet<S: SocketSpec, STATIC: AsRef<Path>>( |
|
|
proxy_redirect off;
|
|
|
proxy_redirect off;
|
|
|
}}",
|
|
|
}}",
|
|
|
static_path.as_ref().to_str().unwrap(),
|
|
|
static_path.as_ref().to_str().unwrap(),
|
|
|
socket_path.to_nginx()
|
|
|
|
|
|
|
|
|
socket_path.to_proxy_pass()
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
|
|
pub fn uwsgi_snippet<S: SocketSpec, STATIC: AsRef<Path>>(
|
|
|
|
|
|
socket_path: S,
|
|
|
|
|
|
static_path: STATIC,
|
|
|
|
|
|
) -> String {
|
|
|
|
|
|
format!(
|
|
|
|
|
|
"root {};
|
|
|
|
|
|
|
|
|
|
|
|
location / {{
|
|
|
|
|
|
try_files $uri @proxy;
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
|
|
location @proxy {{
|
|
|
|
|
|
include uwsgi_params;
|
|
|
|
|
|
uwsgi_pass {};
|
|
|
|
|
|
}}",
|
|
|
|
|
|
static_path.as_ref().to_str().unwrap(),
|
|
|
|
|
|
socket_path.to_uwsgi_pass()
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|