diff --git a/games/mana-games/apps/web/Dockerfile b/games/mana-games/apps/web/Dockerfile new file mode 100644 index 000000000..490dcf9c9 --- /dev/null +++ b/games/mana-games/apps/web/Dockerfile @@ -0,0 +1,29 @@ +# syntax=docker/dockerfile:1 +FROM sveltekit-base:local AS builder + +ARG PUBLIC_MANA_CORE_AUTH_URL=http://mana-auth:3001 +ENV PUBLIC_MANA_CORE_AUTH_URL=$PUBLIC_MANA_CORE_AUTH_URL + +COPY games/mana-games/apps/web ./games/mana-games/apps/web + +RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \ + pnpm install --no-frozen-lockfile --ignore-scripts + +WORKDIR /app/games/mana-games/apps/web +RUN pnpm exec svelte-kit sync +RUN NODE_OPTIONS="--max-old-space-size=4096" pnpm build + +FROM node:20-alpine AS production +WORKDIR /app/games/mana-games/apps/web +COPY --from=builder /app/node_modules/.pnpm /app/node_modules/.pnpm +COPY --from=builder /app/games/mana-games/apps/web/node_modules ./node_modules +COPY --from=builder /app/games/mana-games/apps/web/build ./build +COPY --from=builder /app/games/mana-games/apps/web/package.json ./ + +EXPOSE 5210 +ENV NODE_ENV=production PORT=5210 HOST=0.0.0.0 + +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost:5210/health || exit 1 + +CMD ["node", "build"] diff --git a/games/mana-games/apps/web/src/hooks.client.ts b/games/mana-games/apps/web/src/hooks.client.ts new file mode 100644 index 000000000..b6d927035 --- /dev/null +++ b/games/mana-games/apps/web/src/hooks.client.ts @@ -0,0 +1,12 @@ +import { initErrorTracking, handleSvelteError } from '@manacore/shared-error-tracking/browser'; +import type { HandleClientError } from '@sveltejs/kit'; + +initErrorTracking({ + serviceName: 'mana-games-web', + dsn: (window as any).__PUBLIC_GLITCHTIP_DSN__, + environment: import.meta.env.MODE, +}); + +export const handleError: HandleClientError = ({ error }) => { + handleSvelteError(error); +}; diff --git a/games/mana-games/apps/web/src/hooks.server.ts b/games/mana-games/apps/web/src/hooks.server.ts new file mode 100644 index 000000000..3f4c150e0 --- /dev/null +++ b/games/mana-games/apps/web/src/hooks.server.ts @@ -0,0 +1,28 @@ +import type { Handle } from '@sveltejs/kit'; +import { injectUmamiAnalytics } from '@manacore/shared-utils/analytics-server'; +import { setSecurityHeaders } from '@manacore/shared-utils/security-headers'; + +const PUBLIC_MANA_CORE_AUTH_URL_CLIENT = + process.env.PUBLIC_MANA_CORE_AUTH_URL_CLIENT || process.env.PUBLIC_MANA_CORE_AUTH_URL || ''; +const PUBLIC_BACKEND_URL_CLIENT = + process.env.PUBLIC_BACKEND_URL_CLIENT || process.env.PUBLIC_BACKEND_URL || ''; +const PUBLIC_GLITCHTIP_DSN = process.env.PUBLIC_GLITCHTIP_DSN || ''; + +export const handle: Handle = async ({ event, resolve }) => { + const response = await resolve(event, { + transformPageChunk: ({ html }) => { + const envScript = ``; + return injectUmamiAnalytics(html.replace('', `${envScript}`)); + }, + }); + + setSecurityHeaders(response, { + connectSrc: [PUBLIC_MANA_CORE_AUTH_URL_CLIENT, PUBLIC_BACKEND_URL_CLIENT], + }); + + return response; +}; diff --git a/games/mana-games/apps/web/src/lib/services/feedback.ts b/games/mana-games/apps/web/src/lib/services/feedback.ts new file mode 100644 index 000000000..8e6b1cc93 --- /dev/null +++ b/games/mana-games/apps/web/src/lib/services/feedback.ts @@ -0,0 +1,8 @@ +import { createFeedbackService } from '@manacore/feedback'; +import { authStore } from '$lib/stores/auth.svelte'; + +export const feedbackService = createFeedbackService({ + apiUrl: import.meta.env.DEV ? 'http://localhost:3001' : 'https://auth.mana.how', + appId: 'mana-games', + getAuthToken: async () => authStore.getAccessToken(), +}); diff --git a/games/mana-games/apps/web/src/routes/(app)/feedback/+page.svelte b/games/mana-games/apps/web/src/routes/(app)/feedback/+page.svelte new file mode 100644 index 000000000..a599eb02c --- /dev/null +++ b/games/mana-games/apps/web/src/routes/(app)/feedback/+page.svelte @@ -0,0 +1,11 @@ + + + + Feedback - Mana Games + + +