Skip to content

Commit

Permalink
chore: run dist with environment variables kyb-app
Browse files Browse the repository at this point in the history
  • Loading branch information
pratapalakshmi committed Oct 27, 2024
1 parent 6d1d28d commit 10936ef
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 3 deletions.
13 changes: 11 additions & 2 deletions apps/kyb-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ RUN npm install --legacy-peer-deps
COPY . .

RUN mv /app/.env.example /app/.env

RUN npm run build

ENV PATH="$PATH:./node_modules/.bin"
ENV PATH="$PATH:/app/node_modules/.bin"

EXPOSE 5201

CMD ["npm","run","dev", "--host"]
CMD ["npm", "run", "dev", "--host"]

FROM nginx:stable-alpine as prod

WORKDIR /app

COPY --from=dev /app/dist /usr/share/nginx/html

COPY --from=dev /app/entrypoint.sh /app/entrypoint.sh

COPY example.nginx.conf /etc/nginx/conf.d/default.conf

RUN chmod a+x /app/entrypoint.sh;

EXPOSE 80

ENTRYPOINT [ "/app/entrypoint.sh" ]

CMD ["nginx", "-g", "daemon off;"]
46 changes: 46 additions & 0 deletions apps/kyb-app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env sh

if [[ -z "$VITE_DOMAIN" ]]
then
VITE_DOMAIN="http://localhost:3000"
fi

if [[ -z "$VITE_API_KEY" ]]
then
VITE_API_KEY="secret"
fi

if [[ -z "$VITE_ENVIRONMENT_NAME" ]]
then
VITE_ENVIRONMENT_NAME=local
fi


if [[ -z "$VITE_DEFAULT_EXAMPLE_TOKEN" ]]
then
VITE_DEFAULT_EXAMPLE_TOKEN=12345678-1234-1234-1234-123456789012
fi

if [[ -z "$VITE_SENTRY_AUTH_TOKEN" ]]
then
VITE_SENTRY_AUTH_TOKEN=""
fi

if [[ -z "$VITE_SENTRY_DSN" ]]
then
VITE_SENTRY_DSN=""
fi

cat << EOF > /usr/share/nginx/html/config.js
globalThis.env = {
VITE_API_URL: "$VITE_DOMAIN/api/v1/",
VITE_API_KEY: "$VITE_API_KEY",
VITE_ENVIRONMENT_NAME: "$VITE_ENVIRONMENT_NAME",
VITE_DEFAULT_EXAMPLE_TOKEN: "$VITE_DEFAULT_EXAMPLE_TOKEN",
VITE_SENTRY_AUTH_TOKEN: "$VITE_SENTRY_AUTH_TOKEN",
VITE_SENTRY_DSN: "$VITE_SENTRY_DSN",
}
EOF

# Handle CMD command
exec "$@"
3 changes: 3 additions & 0 deletions apps/kyb-app/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare global {
export var env: { [key: string]: any };
}
1 change: 1 addition & 0 deletions apps/kyb-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>KYB - Collection Flow</title>
<script type="text/javascript" src="/config.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
9 changes: 9 additions & 0 deletions apps/kyb-app/public/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
globalThis.env = {
VITE_API_URL: import.meta.env.VITE_API_URL || 'http://google.com',
VITE_KYB_DEFINITION_ID: import.meta.env.VITE_KYB_DEFINITION_ID || 'kyb_parent_kyc_session_example',
VITE_API_KEY: import.meta.env.VITE_API_KEY || 'secret',
VITE_ENVIRONMENT_NAME: import.meta.env.VITE_ENVIRONMENT_NAME || 'local',
VITE_DEFAULT_EXAMPLE_TOKEN: import.meta.env.VITE_DEFAULT_EXAMPLE_TOKEN || '12345678-1234-1234-1234-123456789012',
VITE_SENTRY_AUTH_TOKEN: import.meta.env.VITE_SENTRY_AUTH_TOKEN || '',
VITE_SENTRY_DSN: import.meta.env.VITE_SENTRY_DSN || '',
};
3 changes: 2 additions & 1 deletion apps/kyb-app/src/common/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as Sentry from '@sentry/react';
import ky, { HTTPError } from 'ky';

export const request = ky.create({
prefixUrl: import.meta.env.VITE_API_URL || `${window.location.origin}/api/v1/`,
//@ts-ignore
prefixUrl: globalThis.env.VITE_API_URL,
retry: {
limit: 1,
statusCodes: [500, 408, 404, 404, 403, 401],
Expand Down
7 changes: 7 additions & 0 deletions apps/kyb-app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { App } from './App';
import { Head } from './Head';
import './i18next';
import './index.css';
import { initializeMonitoring } from '@/initialize-monitoring/initialize-monitoring';
import '../public/config.js?url';

try {
initializeMonitoring();
Expand All @@ -38,3 +40,8 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
</HelmetProvider>
</React.StrictMode>,
);

//@ts-ignore
globalThis.env = globalThis.env || {
API_URL: import.meta.env.VITE_API_URL,
};

0 comments on commit 10936ef

Please sign in to comment.