First off here's the situation:I am developing some web apps for the company I work at. Unfortunately, I'm not actually a developer (by title), so I don't get cool kid permissions like accessing our network remotely. Right now, I'm developing the apps at home outside of our network. But the tools make use of some APIs we have inside our network. To get around this, I basically saved some JSON files of some example responses from these APIs, and I need to "recreate" the API at home.Now regardless of whether I actually set up an "API" with Express or I simply read from a JSON file to simulate the API call, I'll need to write different code for the production and development environment. Perhaps something where the app checks to see if it is in the development environment, and then either calls the real API or my fake API based on that.Is this how something like this would normally be handled? Is there a more elegant way to do this? This what I initially had in mind:const prodURL = "https://ift.tt/C76uQv"; const devURL = "localhost:3000/testapi"; const isDevEnv = determineEnvironment() === "development"; const URL = isDevEnv ? devURL : prodURL ; fetch(URL).then(...); Note: I know I'm giving them free labor by working from home, but I'm OK with it because I'm doing this voluntarily. They never asked me to do this, and the few times they have asked me to develop something on company time, they gave me free reign to move away from my normal duties to do it. I'm kind of a hybrid employee at the moment...
Submitted September 06, 2018 at 06:16PM by PM_ME_A_WEBSITE_IDEA
No comments:
Post a Comment