From 0e9e8c608525272fa5829133fc834e73eb25ca03 Mon Sep 17 00:00:00 2001
From: DutchEllie <personal@quenten.nl>
Date: Wed, 13 Jul 2022 13:12:25 +0200
Subject: [PATCH] Properly do staging

---
 package.json                         |  1 +
 src/components/misc/guestbook.svelte | 14 ++++++++------
 staging.Dockerfile                   | 18 ++++++++++++++++++
 vite.config.js                       |  2 +-
 4 files changed, 28 insertions(+), 7 deletions(-)
 create mode 100644 staging.Dockerfile

diff --git a/package.json b/package.json
index 97e1572..c0bf686 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,7 @@
 	"scripts": {
 		"dev": "vite dev",
 		"build": "vite build",
+		"staging": "vite build --mode staging",
 		"package": "svelte-kit package",
 		"preview": "vite preview",
 		"prepare": "svelte-kit sync",
diff --git a/src/components/misc/guestbook.svelte b/src/components/misc/guestbook.svelte
index 07d4970..d57df16 100644
--- a/src/components/misc/guestbook.svelte
+++ b/src/components/misc/guestbook.svelte
@@ -15,9 +15,11 @@
 	import { onMount } from 'svelte';
 	import { sha256 } from 'js-sha256';
 	import GuestbookEntry from './guestbook/guestbook-entry.svelte';
-	import { page } from '$app/stores';
-import { comment } from 'postcss';
-
+	import { mode } from '$app/env';
+	
+	//const ApiURL = dev ? 'https://api.quenten.nl/api/testing' : 'https://api.quenten.nl/api';
+	//const ApiURL = import.meta.env.APIURL;
+	const ApiURL = mode == 'production' ? 'https://api.quenten.nl/api' : 'https://api.quenten.nl/api/testing';
 	let showError = false;
 	let errorTitle = 'Error';
 	let errorMessage = 'Error message';
@@ -58,7 +60,7 @@ import { comment } from 'postcss';
 		};
 
 		const jsonData = JSON.stringify(data);
-		const res = await fetch('https://api.quenten.nl/api/testing/comment', {
+		const res = await fetch(ApiURL + '/comment', {
 			method: 'POST',
 			body: jsonData
 		});
@@ -91,7 +93,7 @@ import { comment } from 'postcss';
 			return;
 		}
 
-		let newHash = await fetch('https://api.quenten.nl/api/testing/commenthash')
+		let newHash = await fetch(ApiURL + '/commenthash')
 			.then((res) => res.text())
 			.then((t) => {
 				return t;
@@ -107,7 +109,7 @@ import { comment } from 'postcss';
 
 	async function fetchComments() {
 		let comments: Comment[];
-		comments = await fetch('https://api.quenten.nl/api/testing/comment')
+		comments = await fetch(ApiURL + '/comment')
 			.then((res) => res.json())
 			.then((data) => {
 				return data;
diff --git a/staging.Dockerfile b/staging.Dockerfile
new file mode 100644
index 0000000..cf3d86b
--- /dev/null
+++ b/staging.Dockerfile
@@ -0,0 +1,18 @@
+FROM node:18.2.0-alpine
+
+WORKDIR /app
+COPY . .
+RUN npm ci
+RUN npm audit fix
+RUN npm run staging
+
+FROM node:18.2.0-alpine
+
+WORKDIR /app
+COPY --from=0 /app/package*.json ./
+RUN npm ci --ignore-scripts
+RUN npm audit fix
+COPY --from=0 /app/build ./
+
+EXPOSE 3000
+CMD ["node", "./index.js"]
\ No newline at end of file
diff --git a/vite.config.js b/vite.config.js
index 8747050..bc0e201 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -2,7 +2,7 @@ import { sveltekit } from '@sveltejs/kit/vite';
 
 /** @type {import('vite').UserConfig} */
 const config = {
-	plugins: [sveltekit()]
+	plugins: [sveltekit()],
 };
 
 export default config;