add public URL conf option
This commit is contained in:
parent
11ea834835
commit
cb77c609dd
5 changed files with 13 additions and 4 deletions
|
@ -2,3 +2,6 @@ debug = true
|
|||
|
||||
[database]
|
||||
url = "postgres://ztoa:0zpVXAVK20@localhost:5432/ztoa"
|
||||
|
||||
[app]
|
||||
public_url = "http://localhost:3742/"
|
||||
|
|
|
@ -11,6 +11,7 @@ pub struct Database {
|
|||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct App {
|
||||
pub listen: SocketAddr,
|
||||
pub public_url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
|
|
|
@ -39,8 +39,6 @@ pub async fn subscribe(
|
|||
return Err(SubscribeError::InvalidEmail);
|
||||
}
|
||||
|
||||
debug!("email sent");
|
||||
|
||||
let mut txn = db.begin().await.context("start database transaction")?;
|
||||
|
||||
let subscriber_id = Uuid::new_v4();
|
||||
|
@ -84,10 +82,15 @@ pub async fn subscribe(
|
|||
.parse()
|
||||
.map_err(|_| SubscribeError::InvalidEmail)?,
|
||||
"Test".to_owned(),
|
||||
format!("Please confirm your subscription: https://example.com/subscriptions/confirm/?token={token}"),
|
||||
format!(
|
||||
"Please confirm your subscription: {}subscriptions/confirm/?token={token}",
|
||||
conf.app.public_url
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
|
||||
debug!("email sent");
|
||||
|
||||
txn.commit().await.context("commit transaction")?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -52,6 +52,8 @@ impl TestServer {
|
|||
let server = ZeroToAxum::serve(Conf {
|
||||
app: conf::App {
|
||||
listen: "[::]:0".parse().unwrap(),
|
||||
// TODO: how do I both configure this and use a random port?
|
||||
public_url: "http://localhost/".to_string(),
|
||||
},
|
||||
database: conf::Database { url },
|
||||
debug: true,
|
||||
|
|
|
@ -24,7 +24,7 @@ async fn subscribe_succeeds_with_valid_input() -> Result<()> {
|
|||
assert!(
|
||||
server
|
||||
.mock_smtp_server
|
||||
.assert(MailAssertion::new().body_matches(Regex::new(r"example\.com")?)),
|
||||
.assert(MailAssertion::new().body_matches(Regex::new(r"http\:\/\/localhost\/")?)),
|
||||
"email sent has link"
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue