diff --git a/apps/kyb-app/Dockerfile b/apps/kyb-app/Dockerfile index b7e795156f..032a90c9f5 100644 --- a/apps/kyb-app/Dockerfile +++ b/apps/kyb-app/Dockerfile @@ -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;"] diff --git a/apps/kyb-app/entrypoint.sh b/apps/kyb-app/entrypoint.sh new file mode 100644 index 0000000000..fc90b86708 --- /dev/null +++ b/apps/kyb-app/entrypoint.sh @@ -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 "$@" diff --git a/apps/kyb-app/global.d.ts b/apps/kyb-app/global.d.ts new file mode 100644 index 0000000000..3e423828a7 --- /dev/null +++ b/apps/kyb-app/global.d.ts @@ -0,0 +1,3 @@ +declare global { + export var env: { [key: string]: any }; +} diff --git a/apps/kyb-app/index.html b/apps/kyb-app/index.html index ce258bdc02..d9ecbcf049 100644 --- a/apps/kyb-app/index.html +++ b/apps/kyb-app/index.html @@ -7,6 +7,7 @@ KYB - Collection Flow +
diff --git a/apps/kyb-app/public/config.js b/apps/kyb-app/public/config.js new file mode 100644 index 0000000000..f28f120b8c --- /dev/null +++ b/apps/kyb-app/public/config.js @@ -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', + VITE_SENTRY_AUTH_TOKEN: import.meta.env.VITE_SENTRY_AUTH_TOKEN || '', + VITE_SENTRY_DSN: import.meta.env.VITE_SENTRY_DSN || '', +}; diff --git a/apps/kyb-app/src/common/utils/request.ts b/apps/kyb-app/src/common/utils/request.ts index d487a14839..41d0031137 100644 --- a/apps/kyb-app/src/common/utils/request.ts +++ b/apps/kyb-app/src/common/utils/request.ts @@ -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 || `${window.location.origin}/api/v1/`, retry: { limit: 1, statusCodes: [500, 408, 404, 404, 403, 401],