Default fetch host
Answered
Saltwater Crocodile posted this in #help-forum
Saltwater CrocodileOP
Is there a way to configure fetch to get a host based on an environment variable and reference it with a tag or something so that I don't have to https://... ceremony to every fetch call? And so that my ide can properly hint to route paths?
Answered by Coffee Coke
you can create function and import it whenever you want if you want it:
and also can add option for adding query keys
const url = (link) => `https://${link}`;
and also can add option for adding query keys
4 Replies
@Saltwater Crocodile Is there a way to configure fetch to get a host based on an environment variable and reference it with a tag or something so that I don't have to https://... ceremony to every fetch call? And so that my ide can properly hint to route paths?
add your environentals in the
.env file and getit by proccess.env.KEY and return your link based that KEY, when deploying change KEY to production or whatever you will name it
.env file and getit by proccess.env.KEY and return your link based that KEY, when deploying change KEY to production or whatever you will name it
Saltwater CrocodileOP
But that still makes me have to compose the url on every fetch call; right?
@Saltwater Crocodile But that still makes me have to compose the url on every fetch call; right?
you can create function and import it whenever you want if you want it:
and also can add option for adding query keys
const url = (link) => `https://${link}`;
and also can add option for adding query keys
Answer
Saltwater CrocodileOP
Thanks. I'll do that. Some frameworks allow you go configure global http clients and inject them. Was hoping for something like that, but if it's not necessary.