Skip to content

Commit

Permalink
fix: read app config before env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Dec 1, 2021
1 parent 147923f commit 9ed1e3d
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 16 deletions.
11 changes: 8 additions & 3 deletions packages/app-admin-cognito/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import ForgotPassword from "~/views/ForgotPassword";
import SetNewPassword from "~/views/SetNewPassword";
import SignedIn from "~/views/SignedIn";
import { useSecurity } from "@webiny/app-security";
import { config as appConfig } from "@webiny/app/config";

const createApolloLinkPlugin = () => {
return new ApolloLinkPlugin(() => {
return setContext(async (_, { headers }) => {
Expand All @@ -41,9 +43,12 @@ const createApolloLinkPlugin = () => {
};

const defaultOptions = {
region: process.env.REACT_APP_USER_POOL_REGION,
userPoolId: process.env.REACT_APP_USER_POOL_ID,
userPoolWebClientId: process.env.REACT_APP_USER_POOL_WEB_CLIENT_ID
region: appConfig.getKey("USER_POOL_REGION", process.env.REACT_APP_USER_POOL_REGION),
userPoolId: appConfig.getKey("USER_POOL_ID", process.env.REACT_APP_USER_POOL_ID),
userPoolWebClientId: appConfig.getKey(
"USER_POOL_WEB_CLIENT_ID",
process.env.REACT_APP_USER_POOL_WEB_CLIENT_ID
)
};

export interface Props {
Expand Down
8 changes: 6 additions & 2 deletions packages/app-admin-users-cognito/src/plugins/cognito.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ import { UIViewPlugin } from "@webiny/app-admin/ui/UIView";
import { UsersFormView } from "~/ui/views/Users/UsersFormView";
import { PasswordElement } from "@webiny/app-admin/ui/elements/form/PasswordElement";
import { createPasswordValidator, PasswordPolicy } from "~/createPasswordValidator";
import { config as appConfig } from "@webiny/app/config";

export default (): PluginCollection => {
const passwordValidator = createPasswordValidator(
JSON.parse(process.env.REACT_APP_USER_POOL_PASSWORD_POLICY) as PasswordPolicy
const passwordValidatorPolicy = appConfig.getKey<PasswordPolicy>(
"USER_POOL_PASSWORD_POLICY",
JSON.parse(process.env.REACT_APP_USER_POOL_PASSWORD_POLICY)
);

const passwordValidator = createPasswordValidator(passwordValidatorPolicy);
return [
// Add password input to admin user installation
new ViewPlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Cell, Grid } from "@webiny/ui/Grid";
import { validation } from "@webiny/validation";
import AvatarImage from "../../components/AvatarImage";
import { GET_CURRENT_USER, UPDATE_CURRENT_USER } from "./graphql";
import { config as appConfig } from "@webiny/app/config";

import {
SimpleForm,
Expand Down Expand Up @@ -65,7 +66,10 @@ const UserAccountForm = () => {

const user = currentUser.loading ? {} : currentUser.data.adminUsers.user.data;

const emailIsDisabled = process.env.REACT_APP_ADMIN_USER_CAN_CHANGE_EMAIL === "false";
const emailIsDisabled = appConfig.getKey(
"ADMIN_USER_CAN_CHANGE_EMAIL",
process.env.REACT_APP_ADMIN_USER_CAN_CHANGE_EMAIL === "false"
);

return (
<Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { GroupAutocompleteElement } from "~/ui/elements/GroupAutocompleteElement
import { UseUserForm, useUserForm } from "~/ui/views/Users/hooks/useUserForm";
import { FormView } from "@webiny/app-admin/ui/views/FormView";
import { FormElementRenderProps } from "@webiny/app-admin/ui/elements/form/FormElement";
import { config as appConfig } from "@webiny/app/config";

const FormWrapper = styled("div")({
margin: "0 100px"
Expand Down Expand Up @@ -139,7 +140,10 @@ export class UsersFormView extends UIView {
return false;
}

return process.env.REACT_APP_ADMIN_USER_CAN_CHANGE_EMAIL === "false";
return appConfig.getKey(
"ADMIN_USER_CAN_CHANGE_EMAIL",
process.env.REACT_APP_ADMIN_USER_CAN_CHANGE_EMAIL === "false"
);
}
})
);
Expand Down
5 changes: 4 additions & 1 deletion packages/app-file-manager/src/admin/plugins/installation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Alert } from "@webiny/ui/Alert";
import { CircularProgress } from "@webiny/ui/Progress";
import { SimpleForm, SimpleFormContent } from "@webiny/app-admin/components/SimpleForm";
import styled from "@emotion/styled";
import { config as appConfig } from "@webiny/app/config";

const SimpleFormPlaceholder = styled.div({
minHeight: 300,
Expand Down Expand Up @@ -41,11 +42,13 @@ const FMInstaller = ({ onInstalled }) => {
const client = useApolloClient();
const [error, setError] = useState(null);

const apiUrl = appConfig.getKey("API_URL", process.env.REACT_APP_API_URL);

useEffect(() => {
client
.mutate({
mutation: INSTALL,
variables: { srcPrefix: process.env.REACT_APP_API_URL + "/files" }
variables: { srcPrefix: apiUrl + "/files" }
})
.then(({ data }) => {
const { error } = data.fileManager.install;
Expand Down
4 changes: 3 additions & 1 deletion packages/app-graphql-playground/src/plugins/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useSecurity } from "@webiny/app-security";
import { CircularProgress } from "@webiny/ui/Progress";
import { playgroundDialog, PlaygroundContainer } from "./Playground.styles";
import { settings } from "./settings";
import { config as appConfig } from "@webiny/app/config";

const withHeaders = (link, headers) => {
return ApolloLink.from([
Expand Down Expand Up @@ -53,7 +54,8 @@ const Playground = ({ createApolloClient }) => {

const createApolloLink = useCallback(({ endpoint, headers }) => {
// If the request endpoint is not know to us, return the first available
if (!endpoint.includes(process.env.REACT_APP_API_URL)) {
const apiUrl = appConfig.getKey("API_URL", process.env.REACT_APP_API_URL);
if (!endpoint.includes(apiUrl)) {
return { link: withHeaders(Object.values(links.current)[0], headers) };
}

Expand Down
4 changes: 3 additions & 1 deletion packages/app-graphql-playground/src/plugins/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import placeholder from "!!raw-loader!./placeholder.graphql";
import { NavigationMenuElement } from "@webiny/app-admin/ui/elements/NavigationMenuElement";
import { UIViewPlugin } from "@webiny/app-admin/ui/UIView";
import { NavigationView } from "@webiny/app-admin/ui/views/NavigationView";
import { config as appConfig } from "@webiny/app/config";

type GraphQLPlaygroundOptions = {
createApolloClient(params: { uri: string }): ApolloClient<any>;
Expand Down Expand Up @@ -52,9 +53,10 @@ export default (options: GraphQLPlaygroundOptions) => [
{
type: "graphql-playground-tab",
tab() {
const apiUrl = appConfig.getKey("API_URL", process.env.REACT_APP_API_URL);
return {
name: "Main API",
endpoint: process.env.REACT_APP_API_URL + "/graphql",
endpoint: apiUrl + "/graphql",
headers: {},
query: placeholder
};
Expand Down
6 changes: 4 additions & 2 deletions packages/app-headless-cms/src/admin/contexts/Cms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import ApolloClient from "apollo-client";
import { useI18N } from "@webiny/app-i18n/hooks/useI18N";
import { CircularProgress } from "@webiny/ui/Progress";
import { config as appConfig } from "@webiny/app/config";

export interface CmsContextValue {
getApolloClient(locale: string): ApolloClient<any>;
Expand All @@ -19,6 +20,7 @@ type CmsProviderProps = {
};

export function CmsProvider(props: CmsProviderProps) {
const apiUrl = appConfig.getKey('API_URL', process.env.REACT_APP_API_URL);
const { getCurrentLocale } = useI18N();

const currentLocale = getCurrentLocale("content");
Expand All @@ -31,15 +33,15 @@ export function CmsProvider(props: CmsProviderProps) {

if (currentLocale && !apolloClientsCache[currentLocale]) {
apolloClientsCache[currentLocale] = props.createApolloClient({
uri: `${process.env.REACT_APP_API_URL}/cms/manage/${currentLocale}`
uri: `${apiUrl}/cms/manage/${currentLocale}`
});
}

const value = {
getApolloClient(locale: string) {
if (!apolloClientsCache[locale]) {
apolloClientsCache[locale] = props.createApolloClient({
uri: `${process.env.REACT_APP_API_URL}/cms/manage/${locale}`
uri: `${apiUrl}/cms/manage/${locale}`
});
}
return apolloClientsCache[locale];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import raw from "raw.macro";
const manageQuery = raw("./placeholder.manage.graphql");
const readQuery = raw("./placeholder.read.graphql");
const previewQuery = raw("./placeholder.preview.graphql");
import { config as appConfig } from "@webiny/app/config";

const plugins: GraphQLPlaygroundTabPlugin[] = [
{
type: "graphql-playground-tab",
name: "graphql-playground-tab-manage",
tab({ locale, identity }) {
const apiUrl = appConfig.getKey("API_URL", process.env.REACT_APP_API_URL);
if (!identity.getPermission("cms.endpoint.manage")) {
return null;
}

return {
name: "Headless CMS - Manage API",
endpoint: process.env.REACT_APP_API_URL + "/cms/manage/" + locale,
endpoint: apiUrl + "/cms/manage/" + locale,
headers: {},
query: manageQuery
};
Expand All @@ -25,13 +27,14 @@ const plugins: GraphQLPlaygroundTabPlugin[] = [
type: "graphql-playground-tab",
name: "graphql-playground-tab-read",
tab({ locale, identity }) {
const apiUrl = appConfig.getKey("API_URL", process.env.REACT_APP_API_URL);
if (!identity.getPermission("cms.endpoint.read")) {
return null;
}

return {
name: "Headless CMS - Read API",
endpoint: process.env.REACT_APP_API_URL + "/cms/read/" + locale,
endpoint: apiUrl + "/cms/read/" + locale,
headers: {},
query: readQuery
};
Expand All @@ -41,13 +44,14 @@ const plugins: GraphQLPlaygroundTabPlugin[] = [
type: "graphql-playground-tab",
name: "graphql-playground-tab-preview",
tab({ locale, identity }) {
const apiUrl = appConfig.getKey("API_URL", process.env.REACT_APP_API_URL);
if (!identity.getPermission("cms.endpoint.preview")) {
return null;
}

return {
name: "Headless CMS - Preview API",
endpoint: process.env.REACT_APP_API_URL + "/cms/preview/" + locale,
endpoint: apiUrl + "/cms/preview/" + locale,
headers: {},
query: previewQuery
};
Expand Down
6 changes: 5 additions & 1 deletion packages/app-tenancy/src/contexts/Tenancy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { default as localStorage } from "store";
import { plugins } from "@webiny/plugins";
import { TenantHeaderLinkPlugin } from "@webiny/app/plugins/TenantHeaderLinkPlugin";
export const TenancyContext = React.createContext(null);
import { config as appConfig } from "@webiny/app/config";

export interface Tenant {
id: string;
Expand Down Expand Up @@ -59,7 +60,10 @@ export const TenancyProvider = props => {
() => ({
tenant: currentTenant,
setTenant: changeTenant,
isMultiTenant: process.env.REACT_APP_WEBINY_MULTI_TENANCY === "true"
isMultiTenant: appConfig.getKey(
"WEBINY_MULTI_TENANCY",
process.env.REACT_APP_WEBINY_MULTI_TENANCY === "true"
)
}),
[currentTenant]
);
Expand Down

0 comments on commit 9ed1e3d

Please sign in to comment.