Merge branch 'hotfix/baseurl-env' into 'master'
Hotfix/baseurl env
- Application searches for BASE_URL in window.BASE_URL,
- Not found? Application searches for BASE_URL in process.env.REACT_APP_BASE_URL
- Not found? Application aborts
- Login form post url is now the apiURL/login (without the api version)
- Logout XHR post url is now the apiURL/logout (without the api version)
See merge request theappsmith/internal-tools-client!256
This commit is contained in:
commit
eae4c5e618
|
|
@ -1,19 +1,24 @@
|
|||
[context.production]
|
||||
[context.production.environment]
|
||||
REACT_APP_ENVIRONMENT = "PRODUCTION"
|
||||
REACT_APP_BASE_URL = "https://api.appsmith.com"
|
||||
|
||||
[context.release]
|
||||
[context.release.environment]
|
||||
REACT_APP_ENVIRONMENT = "STAGING"
|
||||
REACT_APP_BASE_URL = "https://release-api.appsmith.com"
|
||||
|
||||
[context.develop]
|
||||
[context.develop.environment]
|
||||
REACT_APP_ENVIRONMENT = "DEVELOPMENT"
|
||||
REACT_APP_BASE_URL = "https://release-api.appsmith.com"
|
||||
|
||||
[context.a]
|
||||
[context.a.environment]
|
||||
REACT_APP_ENVIRONMENT = "STAGING"
|
||||
REACT_APP_BASE_URL = "https://release-api.appsmith.com"
|
||||
|
||||
[context.b]
|
||||
[context.b.environment]
|
||||
REACT_APP_ENVIRONMENT = "STAGING"
|
||||
REACT_APP_BASE_URL = "https://release-api.appsmith.com"
|
||||
|
|
|
|||
|
|
@ -88,11 +88,11 @@
|
|||
},
|
||||
"scripts": {
|
||||
"analyze": "source-map-explorer 'build/static/js/*.js'",
|
||||
"start": "REACT_APP_ENVIRONMENT=DEVELOPMENT HOST=dev.appsmith.com craco start",
|
||||
"start": "REACT_APP_BASE_URL=https://release-api.appsmith.com REACT_APP_ENVIRONMENT=DEVELOPMENT HOST=dev.appsmith.com craco start",
|
||||
"build": "craco --max-old-space-size=2048 build",
|
||||
"test": "CI=true craco test",
|
||||
"eject": "react-scripts eject",
|
||||
"start-prod": "REACT_APP_ENVIRONMENT=PRODUCTION craco start",
|
||||
"start-prod": "REACT_APP_BASE_URL=https://api.appsmith.com REACT_APP_ENVIRONMENT=PRODUCTION craco start",
|
||||
"storybook": "start-storybook",
|
||||
"cytest": "REACT_APP_TESTING=TESTING REACT_APP_ENVIRONMENT=DEVELOPMENT craco start & ./node_modules/.bin/cypress open",
|
||||
"build-storybook": "build-storybook -c .storybook -o .storybook-out"
|
||||
|
|
|
|||
|
|
@ -19,5 +19,8 @@
|
|||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<script type="text/javascript">
|
||||
window.BASE_URL = "___BASE_URL___";
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import {
|
|||
} from "constants/ApiConstants";
|
||||
import { ActionApiResponse } from "./ActionAPI";
|
||||
import { AUTH_LOGIN_URL } from "constants/routes";
|
||||
const { apiUrl, baseUrl } = getAppsmithConfigs();
|
||||
const { baseUrl, apiUrl } = getAppsmithConfigs();
|
||||
|
||||
//TODO(abhinav): Refactor this to make more composable.
|
||||
export const apiRequestConfig = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { AxiosPromise } from "axios";
|
||||
import Api from "./Api";
|
||||
import { ApiResponse } from "./ApiResponses";
|
||||
import { getAppsmithConfigs } from "configs";
|
||||
|
||||
export interface LoginUserRequest {
|
||||
email: string;
|
||||
|
|
@ -55,7 +54,7 @@ class UserApi extends Api {
|
|||
static inviteUserURL = "v1/users/invite";
|
||||
static verifyInviteTokenURL = `${UserApi.inviteUserURL}/verify`;
|
||||
static confirmUserInviteURL = `${UserApi.inviteUserURL}/confirm`;
|
||||
static logoutURL = "/logout";
|
||||
static logoutURL = "v1/logout";
|
||||
|
||||
static createUser(
|
||||
request: CreateUserRequest,
|
||||
|
|
@ -103,11 +102,7 @@ class UserApi extends Api {
|
|||
}
|
||||
|
||||
static logoutUser(): AxiosPromise<ApiResponse> {
|
||||
const { baseUrl } = getAppsmithConfigs();
|
||||
return Api.post(UserApi.logoutURL, undefined, undefined, {
|
||||
baseURL: baseUrl,
|
||||
withCredentials: true,
|
||||
});
|
||||
return Api.post(UserApi.logoutURL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { SENTRY_STAGE_CONFIG } from "constants/ThirdPartyConstants";
|
||||
import { STAGE_BASE_URL } from "constants/ApiConstants";
|
||||
import { AppsmithUIConfigs } from "./types";
|
||||
|
||||
const devConfig: AppsmithUIConfigs = {
|
||||
const devConfig = (baseUrl: string): AppsmithUIConfigs => ({
|
||||
sentry: {
|
||||
enabled: false,
|
||||
config: SENTRY_STAGE_CONFIG,
|
||||
|
|
@ -14,7 +13,7 @@ const devConfig: AppsmithUIConfigs = {
|
|||
enabled: false,
|
||||
},
|
||||
apiUrl: "/api/",
|
||||
baseUrl: STAGE_BASE_URL,
|
||||
};
|
||||
baseUrl,
|
||||
});
|
||||
|
||||
export default devConfig;
|
||||
|
|
|
|||
|
|
@ -2,21 +2,35 @@ import prodConfig from "./prod.config";
|
|||
import stageConfig from "./stage.config";
|
||||
import devConfig from "./dev.config";
|
||||
import { AppsmithUIConfigs } from "./types";
|
||||
declare global {
|
||||
interface Window {
|
||||
BASE_URL: string;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(Abhinav): See if this is called so many times, that we may need memoization.
|
||||
export const getAppsmithConfigs = (): AppsmithUIConfigs => {
|
||||
const WINDOW_BASE_URL: string = window.BASE_URL;
|
||||
const REACT_APP_BASE_URL: string | undefined = process.env.REACT_APP_BASE_URL;
|
||||
|
||||
const BASE_URL =
|
||||
WINDOW_BASE_URL === "___BASE_URL___" ? REACT_APP_BASE_URL : WINDOW_BASE_URL;
|
||||
|
||||
if (!BASE_URL) {
|
||||
throw Error("NO API Endpont defined - aborting");
|
||||
}
|
||||
switch (process.env.REACT_APP_ENVIRONMENT) {
|
||||
case "PRODUCTION":
|
||||
return prodConfig;
|
||||
return prodConfig(BASE_URL);
|
||||
case "STAGING":
|
||||
return stageConfig;
|
||||
return stageConfig(BASE_URL);
|
||||
case "DEVELOPMENT":
|
||||
return devConfig;
|
||||
return devConfig(BASE_URL);
|
||||
default:
|
||||
console.log(
|
||||
"Unknown environment set: ",
|
||||
process.env.REACT_APP_ENVIRONMENT,
|
||||
);
|
||||
devConfig.apiUrl = "";
|
||||
return devConfig;
|
||||
return devConfig(BASE_URL);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@ import {
|
|||
HOTJAR_PROD_HJID,
|
||||
HOTJAR_PROD_HJSV,
|
||||
} from "constants/ThirdPartyConstants";
|
||||
import { PROD_BASE_URL } from "constants/ApiConstants";
|
||||
import { AppsmithUIConfigs } from "./types";
|
||||
|
||||
export const prodConfig: AppsmithUIConfigs = {
|
||||
export const prodConfig = (baseUrl: string): AppsmithUIConfigs => ({
|
||||
sentry: {
|
||||
enabled: true,
|
||||
config: SENTRY_PROD_CONFIG,
|
||||
|
|
@ -22,7 +21,7 @@ export const prodConfig: AppsmithUIConfigs = {
|
|||
enabled: true,
|
||||
},
|
||||
apiUrl: "/api/",
|
||||
baseUrl: PROD_BASE_URL,
|
||||
};
|
||||
baseUrl,
|
||||
});
|
||||
|
||||
export default prodConfig;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { SENTRY_STAGE_CONFIG } from "constants/ThirdPartyConstants";
|
||||
import { STAGE_BASE_URL } from "constants/ApiConstants";
|
||||
import { AppsmithUIConfigs } from "./types";
|
||||
|
||||
const stageConfig: AppsmithUIConfigs = {
|
||||
const stageConfig = (baseUrl: string): AppsmithUIConfigs => ({
|
||||
sentry: {
|
||||
enabled: true,
|
||||
config: SENTRY_STAGE_CONFIG,
|
||||
|
|
@ -14,7 +13,7 @@ const stageConfig: AppsmithUIConfigs = {
|
|||
enabled: false,
|
||||
},
|
||||
apiUrl: "/api/",
|
||||
baseUrl: STAGE_BASE_URL,
|
||||
};
|
||||
baseUrl,
|
||||
});
|
||||
|
||||
export default stageConfig;
|
||||
|
|
|
|||
|
|
@ -2,24 +2,17 @@ export type ContentType =
|
|||
| "application/json"
|
||||
| "application/x-www-form-urlencoded";
|
||||
|
||||
export const STAGE_BASE_URL = "https://release-api.appsmith.com";
|
||||
export const PROD_BASE_URL = "https://api.appsmith.com";
|
||||
|
||||
export const REQUEST_TIMEOUT_MS = 10000;
|
||||
|
||||
export const API_REQUEST_HEADERS: APIHeaders = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
export const FORM_REQUEST_HEADERS: APIHeaders = {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
};
|
||||
|
||||
export const OAuthURL = "/oauth2/authorization";
|
||||
export const GoogleOAuthURL = `${OAuthURL}/google`;
|
||||
export const GithubOAuthURL = `${OAuthURL}/github`;
|
||||
|
||||
export const LOGIN_SUBMIT_PATH = "/login";
|
||||
export const LOGIN_SUBMIT_PATH = "login";
|
||||
|
||||
export interface APIException {
|
||||
error: number;
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export const Login = (props: LoginFormProps) => {
|
|||
forgotPasswordURL += `?email=${props.emailValue}`;
|
||||
}
|
||||
|
||||
const { baseUrl } = getAppsmithConfigs();
|
||||
const { baseUrl, apiUrl } = getAppsmithConfigs();
|
||||
|
||||
return (
|
||||
<AuthCardContainer>
|
||||
|
|
@ -108,7 +108,10 @@ export const Login = (props: LoginFormProps) => {
|
|||
<h5>{LOGIN_PAGE_SUBTITLE}</h5>
|
||||
</AuthCardHeader>
|
||||
<AuthCardBody>
|
||||
<SpacedSubmitForm method="POST" action={baseUrl + LOGIN_SUBMIT_PATH}>
|
||||
<SpacedSubmitForm
|
||||
method="POST"
|
||||
action={baseUrl + apiUrl + "v1/" + LOGIN_SUBMIT_PATH}
|
||||
>
|
||||
<FormGroup
|
||||
intent={error ? "danger" : "none"}
|
||||
label={LOGIN_PAGE_EMAIL_INPUT_LABEL}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user