Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Make domain available to Postgres #26

Closed
singingwolfboy opened this issue Jun 24, 2019 · 4 comments
Closed

Make domain available to Postgres #26

singingwolfboy opened this issue Jun 24, 2019 · 4 comments

Comments

@singingwolfboy
Copy link
Contributor

I'm setting up a task queue system to send emails to newly-registered users to validate that they own their email address. However, these emails need to contain a link back to the running application, which means that the job needs to know what domain/port the application is running on. I'm thinking that the best way to do that would be to encode that information into the job payload, which means that the Postgres trigger function needs to know this information.

We're already using pgSettings to set the user_id, so I figure that we could do the same thing for setting the domain, based on the value of httpServer.address(). I'm just not sure of the best way to do this, or whether it belongs in the jwt namespace or elsewhere. Hence, I'm filing this issue! Can I please get some guidance here?

@singingwolfboy
Copy link
Contributor Author

After some further research, I'm thinking it might be best to implement a sites table in the database, similar to Django's "sites" framework. Does that seem reasonable?

@benjie
Copy link
Member

benjie commented Jun 26, 2019

In other apps I use the https://github.com/graphile/worker using the same envvars as the main application, which has the ROOT_URL envvar available so it knows where to link to:

export ROOT_URL="http://\$ROOT_DOMAIN"

I'd advise this approach, it also means that if the user visits the application on the wrong host (e.g. missing www, forgot https://, etc) the email will link to a consistently correct place.

@singingwolfboy
Copy link
Contributor Author

Ah, I didn't notice the ROOT_URL envvar. Thanks!

@benjie
Copy link
Member

benjie commented Jun 26, 2019

No problem 👍

@benjie benjie closed this as completed Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants