feat: add backend_url config option
Required for refresh_token cookie to work properly
This commit is contained in:
parent
4fce262551
commit
6783bd22a7
6 changed files with 12 additions and 14 deletions
|
@ -89,6 +89,6 @@ pub async fn response(
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.cookie(new_refresh_token_cookie(refresh_token))
|
.cookie(new_refresh_token_cookie(&data.config, refresh_token))
|
||||||
.json(Response { access_token }))
|
.json(Response { access_token }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub async fn res(req: HttpRequest, data: web::Data<Data>) -> Result<HttpResponse
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(HttpResponse::Ok()
|
return Ok(HttpResponse::Ok()
|
||||||
.cookie(new_refresh_token_cookie(refresh_token))
|
.cookie(new_refresh_token_cookie(&data.config, refresh_token))
|
||||||
.json(Response { access_token }));
|
.json(Response { access_token }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ pub async fn res(
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(HttpResponse::Ok()
|
return Ok(HttpResponse::Ok()
|
||||||
.cookie(new_refresh_token_cookie(refresh_token))
|
.cookie(new_refresh_token_cookie(&data.config, refresh_token))
|
||||||
.json(Response { access_token }));
|
.json(Response { access_token }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,8 @@ pub struct CacheDatabase {
|
||||||
struct WebBuilder {
|
struct WebBuilder {
|
||||||
ip: Option<String>,
|
ip: Option<String>,
|
||||||
port: Option<u16>,
|
port: Option<u16>,
|
||||||
base_path: Option<String>,
|
|
||||||
frontend_url: Url,
|
frontend_url: Url,
|
||||||
|
backend_url: Option<Url>,
|
||||||
_ssl: Option<bool>,
|
_ssl: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ impl ConfigBuilder {
|
||||||
let web = Web {
|
let web = Web {
|
||||||
ip: self.web.ip.unwrap_or(String::from("0.0.0.0")),
|
ip: self.web.ip.unwrap_or(String::from("0.0.0.0")),
|
||||||
port: self.web.port.unwrap_or(8080),
|
port: self.web.port.unwrap_or(8080),
|
||||||
base_path: self.web.base_path.unwrap_or("".to_string()),
|
frontend_url: self.web.frontend_url.clone(),
|
||||||
frontend_url: self.web.frontend_url,
|
backend_url: self.web.backend_url.or_else(|| self.web.frontend_url.join("/api").ok()).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let endpoint = match &*self.bunny.endpoint {
|
let endpoint = match &*self.bunny.endpoint {
|
||||||
|
@ -148,8 +148,8 @@ pub struct Config {
|
||||||
pub struct Web {
|
pub struct Web {
|
||||||
pub ip: String,
|
pub ip: String,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub base_path: String,
|
|
||||||
pub frontend_url: Url,
|
pub frontend_url: Url,
|
||||||
|
pub backend_url: Url,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
@ -155,7 +155,7 @@ async fn main() -> Result<(), Error> {
|
||||||
App::new()
|
App::new()
|
||||||
.app_data(web::Data::new(data.clone()))
|
.app_data(web::Data::new(data.clone()))
|
||||||
.wrap(cors)
|
.wrap(cors)
|
||||||
.service(api::web(&data.config.web.base_path))
|
.service(api::web(&data.config.web.backend_url.path()))
|
||||||
})
|
})
|
||||||
.bind((web.ip, web.port))?
|
.bind((web.ip, web.port))?
|
||||||
.run()
|
.run()
|
||||||
|
|
10
src/utils.rs
10
src/utils.rs
|
@ -16,10 +16,7 @@ use serde::Serialize;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Conn, Data,
|
config::Config, error::Error, schema::users, structs::{HasIsAbove, HasUuid}, Conn, Data
|
||||||
error::Error,
|
|
||||||
schema::users,
|
|
||||||
structs::{HasIsAbove, HasUuid},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub static EMAIL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
pub static EMAIL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||||
|
@ -100,12 +97,13 @@ pub fn get_ws_protocol_header(headers: &HeaderMap) -> Result<&str, Error> {
|
||||||
Ok(auth_value.unwrap())
|
Ok(auth_value.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_refresh_token_cookie(refresh_token: String) -> Cookie<'static> {
|
pub fn new_refresh_token_cookie(config: &Config, refresh_token: String) -> Cookie<'static> {
|
||||||
Cookie::build("refresh_token", refresh_token)
|
Cookie::build("refresh_token", refresh_token)
|
||||||
.http_only(true)
|
.http_only(true)
|
||||||
.secure(true)
|
.secure(true)
|
||||||
.same_site(SameSite::None)
|
.same_site(SameSite::None)
|
||||||
.path("/api")
|
.domain(config.web.backend_url.domain().unwrap().to_string())
|
||||||
|
.path(config.web.backend_url.path().to_string())
|
||||||
.max_age(Duration::days(30))
|
.max_age(Duration::days(30))
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue