Wulf/create-rust-app

[BUG] Hard-coded URL's should be set by environment variable(s)

AnthonyMichaelTDM opened this issue · 6 comments

let link = &format!(
"http://localhost:3000/reset?token={reset_token}",
reset_token = reset_token
);
mail::auth_recover_existent_account::send(&mailer, &user.email, link);
} else {
let link = &format!("http://localhost:300/register");
mail::auth_recover_nonexistent_account::send(&mailer, &item.email, link);
}

As said in the subject, the hard-coded base URL ("http://localhost:3000/") should be set by an environment variable (maybe PUBLIC_BASE_URL or something like that) because in a production environment the recipient of the email, an end-user, will not be running the web server on their local machine, the server will (probably) be hosted on a cloud service provider like Amazon AWS, Linode, etc. and that the user connects to through a browser.

I haven't checked the whole codebase yet, but almost all references to https://localhost:3000 should instead read from an environment variable.

Also, the second link in the code snippet above would be https://localhost:3000, not https://localhost:300

Wulf commented

Thanks for pointing this out @AnthonyMichaelTDM -- I've been considering various solutions to this but haven't landed on one yet. I was hoping to finish the email builder (#37) first in order to have the best DX. Regardless, I guess we'll need to address this sooner rather than later.

There are two issues here that need to be addressed:

  • hardcoded URLs
  • hardcoded mail templates

I think the most pressing of those issues is the hardcoded urls,

for the hardcoded mail templates we could have a trait, like EmailTemplate, that can be passed as an optional variable to the functions that send the emails, allowing users to define their own templates.

I can work on this in the coming days.

Wulf commented

If by functions you mean the auth controller, that’s exactly what I was thinking — it’s the perfect stopgap until we have a complete solution

what do you think I should name the environment variable?

Actually, now that I think about it, if I do the email template trait thing we don't really need an environment variable for the link urls because the user can just change the url in their template

done, check it out in #211 @Wulf and let me know what you think