Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: run dist with environment variables kyb-app #2645

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

pratapalakshmi marked this conversation as resolved.
Show resolved Hide resolved
if [[ -z "$VITE_DOMAIN" ]]
then
VITE_DOMAIN="http://localhost:3000"
fi

if [[ -z "$VITE_API_KEY" ]]
then
VITE_API_KEY="secret"
fi
pratapalakshmi marked this conversation as resolved.
Show resolved Hide resolved

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
pratapalakshmi marked this conversation as resolved.
Show resolved Hide resolved

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
pratapalakshmi marked this conversation as resolved.
Show resolved Hide resolved

# 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 };
}
pratapalakshmi marked this conversation as resolved.
Show resolved Hide resolved
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>
pratapalakshmi marked this conversation as resolved.
Show resolved Hide resolved
pratapalakshmi marked this conversation as resolved.
Show resolved Hide resolved
</head>
<body>
<div id="root"></div>
Expand Down
11 changes: 11 additions & 0 deletions apps/kyb-app/public/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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',
pratapalakshmi marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -4,7 +4,8 @@ import ky, { HTTPError } from 'ky';
import { isExceptionWillBeHandled } from './helpers';

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 || `${window.location.origin}/api/v1/`,
retry: {
limit: 1,
statusCodes: [500, 408, 404, 404, 403, 401],
Expand Down
Loading