Browse Source

dockerized

liontix 9 months ago
parent
commit
bcbc5fd249

+ 3 - 0
.dockerignore

@@ -0,0 +1,3 @@
+node_modules
+.vscode
+dist

+ 2 - 1
.gitignore

@@ -21,4 +21,5 @@ package-lock.json
 # Vite
 vite.config.js.timestamp-*
 vite.config.ts.timestamp-*
-.vscode
+.vscode
+dist

+ 30 - 0
Dockerfile

@@ -0,0 +1,30 @@
+# Use Node.js base image for build stage
+FROM node:alpine AS build
+
+# Set working directory
+WORKDIR /app
+
+# Copy package.json and yarn.lock files
+COPY package.json ./
+
+# Install dependencies using Yarn
+RUN npm i
+
+# Copy the rest of the application code
+COPY . .
+
+# Build the application
+RUN npm run build
+
+# Use Nginx base image for final stage
+FROM nginx:alpine
+
+# Copy the static files from the SvelteKit app's build output directory into the Nginx server directory
+COPY --from=build /app/dist /usr/share/nginx/html
+COPY nginx.conf /etc/nginx/conf.d/default.conf
+
+# Expose port 80
+EXPOSE 80
+
+# Start Nginx server
+CMD ["nginx", "-g", "daemon off;"]

+ 11 - 0
nginx.conf

@@ -0,0 +1,11 @@
+server {
+    listen 80;
+    server_name localhost;
+
+    root /usr/share/nginx/html;
+    index index.html;
+
+    location / {
+        try_files $uri $uri/ /index.html;
+    }
+}

+ 1 - 0
package.json

@@ -31,6 +31,7 @@
 		"vite": "^6.0.0"
 	},
 	"dependencies": {
+		"@sveltejs/adapter-static": "^3.0.8",
 		"@sveltejs/adapter-vercel": "^5.5.2",
 		"beercss": "^3.8.0",
 		"ics": "^3.8.1",

+ 1 - 1
src/lib/lang/en.json

@@ -56,7 +56,7 @@
     "password": "Password",
     "book": "Book",
     "cancel": "Cancel",
-    "week-short": "Short Week (KW)",
+    "week-short": "Calendar Week",
     "times": "Times",
     "actions": "Actions",
     "action-confirm": "Confirm Action"

+ 3 - 17
src/routes/+layout.ts

@@ -1,22 +1,8 @@
 import type { Config } from '@sveltejs/adapter-vercel';
-import { loadTranslations } from '$lib/translations';
 
-/** @type {import('@sveltejs/kit').Load} */
-export const load = async ({ url }) => {
-  const { pathname } = url;
-
-  let initLocale = 'en'; // get from cookie, user session, ...
-
-  console.log(navigator.language);
-
-  if (navigator.language.includes('de')) {
-    initLocale = 'de';    
-  }
-  
-  await loadTranslations(initLocale, pathname); // keep this just before the `return`
-
-  return {};
-}
+export const ssr = false;
+export const csr = true;
+export const prerender = true;
 
 export const config: Config = {
 	runtime: 'nodejs22.x'

+ 0 - 3
src/routes/+page.server.ts

@@ -1,3 +0,0 @@
-export const ssr = false;
-export const csr = true;
-export const prerender = false;

+ 11 - 1
src/routes/+page.svelte

@@ -1,10 +1,20 @@
 <script lang="ts">
 	import { goto } from "$app/navigation";
+	import { loadTranslations } from "$lib/translations";
 	import { onMount } from "svelte";
 
 
-    onMount(() => {
+    onMount(async () => {
         goto("/user/events");
+        let initLocale = 'en'; // get from cookie, user session, ...
+
+        console.log(navigator.language);
+
+        if (navigator.language.includes('de')) {
+        initLocale = 'de';    
+        }
+
+        await loadTranslations(initLocale, "");
     });
 </script>
 

+ 0 - 5
src/routes/api/+layout.ts

@@ -1,5 +0,0 @@
-import type { Config } from '@sveltejs/adapter-vercel';
-
-export const config: Config = {
-	runtime: 'nodejs22.x'
-};

+ 0 - 10
src/routes/api/test/+server.ts

@@ -1,10 +0,0 @@
-import type { RequestHandler } from '@sveltejs/kit';
-
-export const GET: RequestHandler = async ({ request }) => {
-    return new Response(JSON.stringify({message: "test"}), {
-        status: 200,
-        headers: {
-          'Content-Type': 'application/json',
-        },
-      });
-};

+ 10 - 2
svelte.config.js

@@ -1,4 +1,4 @@
-import adapter from '@sveltejs/adapter-auto';
+import adapter from '@sveltejs/adapter-static';
 import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
 
 /** @type {import('@sveltejs/kit').Config} */
@@ -11,7 +11,15 @@ 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({
+			// default options are shown. On some platforms
+			// these options are set automatically — see below
+			pages: 'dist',
+			assets: 'dist',
+			fallback: undefined,
+			precompress: false,
+			strict: true
+		})
 	}
 };