Skip to content

How to set the handler domain based on environment flag #2061

Answered by kettanaito
canrozanes asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @canrozanes. Thanks for the question, it's a good one.

You can achieve what you want by encapsulating that URL logic in a helper function. Something like url():

function url(path) {
  const domain = env.isTesting ? 'http://localhost/api' : 'http:// staging.example.com/api'
}

And then use that function to create URL predicates in request handlers:

http.get(url('/user'), resolver)
http.post('url('/cart/:id'), resolver)

This is the way I recommend you do it.

Note that if your resource paths will remain the same, which they will, I can recommend dropping the domain name from the URL predicate. If your website is deployed at staging.example.com during the !env.isTesting scenario, you can t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kettanaito
Comment options

Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants