diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..89f5c3c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +node_modules +.env +.git +.gitignore +README.md +Dockerfile +.dockerignore +docker-compose.yml +.storybook +stories \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 83b00fa..26e87bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,43 +1,18 @@ -# Use Node.js 18 alpine as base image -FROM node:18-alpine AS base - -# Set working directory +FROM node:20-alpine AS builder WORKDIR /app - -# Copy package files COPY package.json ./ - -# Install dependencies RUN npm install - -# Copy source code COPY . . +RUN DATABASE_URL="postgres://user:pass@localhost:5432/db" npm run build -# Build the application -RUN npm run build - -# Production stage -FROM node:18-alpine AS production - +FROM node:20-alpine AS runner WORKDIR /app +COPY --from=builder /app ./ -# Copy package files -COPY package.json ./ -# Install only production dependencies -RUN npm install --only=production -# Copy built application from build stage -COPY --from=base /app/build ./build -COPY --from=base /app/static ./static -COPY --from=base /app/package.json ./ - -# Expose port +ENV NODE_ENV=production EXPOSE 3000 -# Set environment -ENV NODE_ENV=production -ENV PORT=3000 - # Start the application -CMD ["node", "build"] \ No newline at end of file +CMD ["node", "build"] diff --git a/docker-compose.yml b/docker-compose.yml index 9eb11a9..1db4bc2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: app: build: . ports: - - 3000:3000 + - 3000:4173 env_file: - .env environment: diff --git a/package.json b/package.json index 5d1925c..7364074 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@storybook/addon-svelte-csf": "^5.0.8", "@storybook/addon-vitest": "^9.1.8", "@storybook/sveltekit": "^9.1.8", - "@sveltejs/adapter-auto": "^6.0.0", + "@sveltejs/adapter-node": "^5.3.2", "@sveltejs/kit": "^2.22.0", "@sveltejs/vite-plugin-svelte": "^6.0.0", "@types/node": "^22", diff --git a/src/app.html b/src/app.html index 7d0accb..f99d563 100644 --- a/src/app.html +++ b/src/app.html @@ -3,7 +3,7 @@ - + %sveltekit.head% diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 673c0fe..e64922e 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -9,8 +9,13 @@ export const handle: Handle = async ({ event, resolve }) => { // Skip CSRF check for GET/HEAD requests if (method !== 'GET' && method !== 'HEAD') { // For development, allow requests without origin header or from localhost - if (!origin || origin.includes('localhost') || origin.includes('127.0.0.1')) { - // Allow in development + if ( + !origin || + origin.includes('localhost') || + origin.includes('127.0.0.1') || + origin.includes('demo.ziasvannes.tech') + ) { + // Allow in development and demo } // In production, you would add: else if (origin !== 'yourdomain.com') { return new Response('Forbidden', { status: 403 }); } } diff --git a/svelte.config.js b/svelte.config.js index 1295460..5c670f9 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,4 +1,4 @@ -import adapter from '@sveltejs/adapter-auto'; +import adapter from '@sveltejs/adapter-node'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; /** @type {import('@sveltejs/kit').Config} */ @@ -11,7 +11,10 @@ const config = { // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. // If your environment is not supported, or you settled on a specific environment, switch out the adapter. // See https://svelte.dev/docs/kit/adapters for more information about adapters. - adapter: adapter() + adapter: adapter(), + csrf: { + trustedOrigins: ['http://localhost:3000', 'https://demo.ziasvannes.tech'] + } } }; diff --git a/vite.config.ts b/vite.config.ts index bbf8c7d..f71ae9c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,5 +2,8 @@ import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; export default defineConfig({ - plugins: [sveltekit()] + plugins: [sveltekit()], + preview: { + allowedHosts: ['demo.ziasvannes.tech'] + } });