Skip to content

Commit

Permalink
Separate subdomain for env override (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
parahall authored Jul 13, 2023
1 parent 394d6dc commit 1d72f02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monday-sdk-js",
"version": "0.4.2",
"version": "0.4.3",
"private": false,
"repository": "https://github.com/mondaycom/monday-sdk-js",
"main": "src/index.js",
Expand Down
16 changes: 11 additions & 5 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const { isBrowser } = require("./helpers");

const isNodeDevEnv = !isBrowser && process.env.NODE_ENV === "development";
const getEnvOrDefault = (key, defaultVal) => {
return isNodeDevEnv && typeof process.env[key] !== "undefined" ? process.env[key] : defaultVal;
};

const MONDAY_PROTOCOL = getEnvOrDefault("MONDAY_COM_PROTOCOL", "https");
const MONDAY_DOMAIN = getEnvOrDefault("MONDAY_COM_DOMAIN", "monday.com");
const MONDAY_SUBDOMAIN_API = getEnvOrDefault("MONDAY_SUBDOMAIN_API", "api.");
const MONDAY_OAUTH_SUBDOMAIN = getEnvOrDefault(MONDAY_SUBDOMAIN_API, "auth.");

const MONDAY_PROTOCOL = (isNodeDevEnv && process.env.MONDAY_COM_PROTOCOL) || "https";
const MONDAY_DOMAIN = (isNodeDevEnv && process.env.MONDAY_COM_DOMAIN) || "monday.com";
const MONDAY_API_URL = `${MONDAY_PROTOCOL}://api.${MONDAY_DOMAIN}/v2`;
const MONDAY_OAUTH_URL = `${MONDAY_PROTOCOL}://auth.${MONDAY_DOMAIN}/oauth2/authorize`;
const MONDAY_OAUTH_TOKEN_URL = `${MONDAY_PROTOCOL}://auth.${MONDAY_DOMAIN}/oauth2/token`;
const MONDAY_API_URL = `${MONDAY_PROTOCOL}://${MONDAY_SUBDOMAIN_API}${MONDAY_DOMAIN}/v2`;
const MONDAY_OAUTH_URL = `${MONDAY_PROTOCOL}://${MONDAY_OAUTH_SUBDOMAIN}${MONDAY_DOMAIN}/oauth2/authorize`;
const MONDAY_OAUTH_TOKEN_URL = `${MONDAY_PROTOCOL}://${MONDAY_OAUTH_SUBDOMAIN}${MONDAY_DOMAIN}/oauth2/token`;

module.exports = {
MONDAY_DOMAIN,
Expand Down

0 comments on commit 1d72f02

Please sign in to comment.