SSR
All checks were successful
deploy to production / deploy (push) Successful in 1m7s

This commit is contained in:
Robin Grenzdörfer 2023-12-06 20:11:49 +00:00
parent 82f2bf9233
commit d3b36a6716
24 changed files with 166 additions and 119 deletions

1
.env
View File

@ -5,3 +5,4 @@ UID=100
GID=101 GID=101
RELEASE_ORG_SLUG=webmakers-gmbh RELEASE_ORG_SLUG=webmakers-gmbh
RELEASE_PROJECT_SLUG=allkids_erfurt RELEASE_PROJECT_SLUG=allkids_erfurt
START_SCRIPT=:ssr

View File

@ -6,13 +6,10 @@ module.exports = {
// / is de home // / is de home
if (path == "/") return 1 if (path == "/") return 1
// all other sites are in db
path = path?.replace(/^\//, "")
// filter for path or alternativePaths // filter for path or alternativePaths
const resp = context.db.find("content", { const resp = context.db.find("content", {
filter: { filter: {
$or: [{ path }, { "alternativePaths.path": path }], $or: [{ path }],
}, },
selector: { _id: 1 }, selector: { _id: 1 },
}) })

View File

@ -71,6 +71,7 @@ const { obj2str, log } = require("../lib/utils")
html = "<!-- NO SSR RENDERING -->" html = "<!-- NO SSR RENDERING -->"
} else if (pNotfound) { } else if (pNotfound) {
status = 404 status = 404
console.log("IS 404")
html = "404 NOT FOUND" html = "404 NOT FOUND"
} else { } else {
// try rendering, if error output plain html // try rendering, if error output plain html
@ -137,6 +138,7 @@ const { obj2str, log } = require("../lib/utils")
// @ts-ignore // @ts-ignore
if (context.is404) { if (context.is404) {
status = 404 status = 404
console.log("IS 404")
} else { } else {
cacheIt = true cacheIt = true
} }
@ -154,7 +156,7 @@ const { obj2str, log } = require("../lib/utils")
tpl = tpl.replace("<!--HTML-->", html) tpl = tpl.replace("<!--HTML-->", html)
tpl = tpl.replace("<!--SSR.ERROR-->", error ? "<!--" + error + "-->" : "") tpl = tpl.replace("<!--SSR.ERROR-->", error ? "<!--" + error + "-->" : "")
tpl = tpl.replace("<!--SSR.COMMENT-->", comment ? "<!--" + comment + "-->" : "") tpl = tpl.replace("<!--SSR.COMMENT-->", comment ? "<!--" + comment + "-->" : "")
console.log("CACHE", cacheIt, noCache)
// save cache if adviced // save cache if adviced
if (cacheIt && !noCache) { if (cacheIt && !noCache) {
context.db.create("ssr", { context.db.create("ssr", {

View File

@ -30,7 +30,7 @@ services:
- ./tmp/nonexistent:/nonexistent - ./tmp/nonexistent:/nonexistent
- ./tmp/.npm:/.npm - ./tmp/.npm:/.npm
working_dir: /data working_dir: /data
command: sh -c "yarn install && API_BASE=http://tibiserver:8080/api/v1/_/${TIBI_NAMESPACE} yarn start" command: sh -c "yarn install && API_BASE=http://tibiserver:8080/api/v1/_/${TIBI_NAMESPACE} yarn start${START_SCRIPT}"
expose: expose:
- 3000 - 3000
labels: labels:

View File

@ -83,7 +83,7 @@ if (process.argv[2] == "start") {
) )
// if SSR env variable is set // if SSR env variable is set
console.log(process.env) console.log(process.env, "=========================ENV")
if (process.env.SSR) { if (process.env.SSR) {
// read api/config.yml.env and read SSR_TOKEN variable from it // read api/config.yml.env and read SSR_TOKEN variable from it
const configEnv = fs.readFileSync(__dirname + "/api/config.yml.env", "utf8") const configEnv = fs.readFileSync(__dirname + "/api/config.yml.env", "utf8")

View File

@ -1,6 +1,7 @@
AddType application/javascript .mjs AddType application/javascript .mjs
#DirectoryIndex spa.html #DirectoryIndex spa.html
# notwendig, da sonst über normale url spa.html aufgerufen wird, muss nur datei name sei, der nicht existiert
DirectoryIndex noindex DirectoryIndex noindex
<ifModule mod_rewrite.c> <ifModule mod_rewrite.c>
@ -11,6 +12,8 @@ DirectoryIndex noindex
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-d
# leitet initale request an backend und nicht an spa.html weiter
RewriteRule ^/?(.*)$ http://tibi-server:8080/api/v1/_/allkids_erfurt/ssr?token=owshwerNwoa&url=/$1 [P,QSA,L] RewriteRule ^/?(.*)$ http://tibi-server:8080/api/v1/_/allkids_erfurt/ssr?token=owshwerNwoa&url=/$1 [P,QSA,L]
# standardmäßig wegen deeplink aus google notwendig, da sonst 404
#RewriteRule (.*) /spa.html [QSA,L] #RewriteRule (.*) /spa.html [QSA,L]
</ifModule> </ifModule>

View File

@ -64,6 +64,7 @@
}) })
let cookiesAllowed = false let cookiesAllowed = false
if (typeof window !== "undefined") {
window.addEventListener("ccAccept", (e) => { window.addEventListener("ccAccept", (e) => {
// @ts-ignore test // @ts-ignore test
if (e.detail[1] == cookieName) cookiesAllowed = true if (e.detail[1] == cookieName) cookiesAllowed = true
@ -88,10 +89,25 @@
return false return false
} }
cookiesAllowed = checkCookie("googleAnalytics") cookiesAllowed = checkCookie("googleAnalytics")
}
</script> </script>
<svelte:head> <svelte:head>
{#if cookiesAllowed} {#if cookiesAllowed}
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) --> <!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) --> <!-- Google tag (gtag.js) -->
<!-- Google tag (gtag.js) --> <!-- Google tag (gtag.js) -->

View File

@ -9,11 +9,12 @@
mitte: "center", mitte: "center",
unten: "flex-end", unten: "flex-end",
} }
if (typeof window !== "undefined") {
window.addEventListener("ccAccept", (e) => { window.addEventListener("ccAccept", (e) => {
// @ts-ignore // @ts-ignore
if (e.detail[1] == cookieName) contentShown = true if (e.detail[1] == cookieName) contentShown = true
}) })
}
//isCookieSet isnt really precise //isCookieSet isnt really precise
function checkCookie(cookieName: string) { function checkCookie(cookieName: string) {
// Get all cookies // Get all cookies

View File

@ -29,7 +29,7 @@
// Initial check // Initial check
checkHomePage() checkHomePage()
checkScroll() checkScroll()
if (typeof window !== "undefined") {
// Listen for changes // Listen for changes
window.addEventListener("scroll", checkScroll) window.addEventListener("scroll", checkScroll)
window.addEventListener("popstate", checkHomePage) window.addEventListener("popstate", checkHomePage)
@ -39,6 +39,7 @@
window.removeEventListener("scroll", checkScroll) window.removeEventListener("scroll", checkScroll)
window.removeEventListener("popstate", checkHomePage) window.removeEventListener("popstate", checkHomePage)
} }
}
}) })
let show = false let show = false
$: console.log(show) $: console.log(show)

View File

@ -8,7 +8,6 @@
function changeStateOfSite(menuOn: boolean) { function changeStateOfSite(menuOn: boolean) {
let siteContainer = document.body let siteContainer = document.body
show = menuOn show = menuOn
console.log("TEST")
if (menuOn) siteContainer.style.overflow = "hidden" if (menuOn) siteContainer.style.overflow = "hidden"
else siteContainer.style.overflow = "initial" else siteContainer.style.overflow = "initial"
} }
@ -59,8 +58,9 @@
textElement.style.letterSpacing = `${letterSpacing}px` textElement.style.letterSpacing = `${letterSpacing}px`
}*/ }*/
} }
if (typeof window !== "undefined") {
window.addEventListener("resize", stretchText) window.addEventListener("resize", stretchText)
}
onMount(stretchText) onMount(stretchText)
</script> </script>
@ -186,7 +186,7 @@
<div class="submenu-img"> <div class="submenu-img">
<img <img
src="{`${apiBaseURL}navigation/${$navigation?.id}/${submenu.image?.src}?filter=${ src="{`${apiBaseURL}navigation/${$navigation?.id}/${submenu.image?.src}?filter=${
window.innerWidth > 500 ? 'xl' : 'm' window?.innerWidth > 500 ? 'xl' : 'm'
}`}" }`}"
alt="img" alt="img"
/> />

View File

@ -30,6 +30,7 @@
function imageSlide(images: HTMLImageElement[]) { function imageSlide(images: HTMLImageElement[]) {
let currentImage = 0 let currentImage = 0
images[0].classList.add("show-img") images[0].classList.add("show-img")
if (typeof window !== "undefined") {
let interval = setInterval(() => { let interval = setInterval(() => {
images[currentImage].classList.remove("show-img") images[currentImage].classList.remove("show-img")
currentImage += 1 currentImage += 1
@ -38,17 +39,21 @@
}, 4000) }, 4000)
return () => clearInterval(interval) return () => clearInterval(interval)
} }
}
function pushImages(node: HTMLImageElement) { function pushImages(node: HTMLImageElement) {
images[0] = node images[0] = node
} }
$: { $: {
if (typeof window !== "undefined") {
const images = Array.from(document.getElementsByClassName("img-menu")) as HTMLImageElement[] const images = Array.from(document.getElementsByClassName("img-menu")) as HTMLImageElement[]
if (images.length !== 0) { if (images.length !== 0) {
imageSlide(images) imageSlide(images)
} }
} }
}
function stretchText() { function stretchText() {
let container = document.getElementById("logo-container") let container = document.getElementById("logo-container")
let textElement = document.getElementById("upper") let textElement = document.getElementById("upper")
@ -83,9 +88,10 @@
textElement.style.letterSpacing = `${newLetterSpacing}px` textElement.style.letterSpacing = `${newLetterSpacing}px`
} }
} }
if (typeof window !== "undefined") {
window.addEventListener("resize", stretchText) window.addEventListener("resize", stretchText)
onMount(stretchText) onMount(stretchText)
}
</script> </script>
<ul> <ul>
@ -111,7 +117,7 @@
<button <button
class="button-three" class="button-three"
on:click="{(e) => { on:click="{(e) => {
let element = document.getElementById('menu') let element = document?.getElementById('menu')
if (element) changeStateOfSite(element.classList.contains('show-menu')) if (element) changeStateOfSite(element.classList.contains('show-menu'))
}}" }}"
aria-controls="primary-navigation" aria-controls="primary-navigation"
@ -210,7 +216,7 @@
<img <img
use:pushImages use:pushImages
src="{`${apiBaseURL}navigation/${$navigation.id}/${imgSrc}?filter=${ src="{`${apiBaseURL}navigation/${$navigation.id}/${imgSrc}?filter=${
window.innerWidth > 500 ? 'xl' : 'm' window?.innerWidth > 500 ? 'xl' : 'm'
}`}" }`}"
alt="img" alt="img"
class="img img-menu" class="img img-menu"

View File

@ -31,14 +31,17 @@
firstSlideH1.classList.add("active") firstSlideH1.classList.add("active")
} }
} }
if (typeof window !== "undefined") {
const el = document.getElementById("HP") const el = document.getElementById("HP")
let heightOfEl = el?.clientHeight let heightOfEl = el?.clientHeight
const hp = document.getElementById("Homepage") const hp = document.getElementById("Homepage")
const homepage_placeholder = document.getElementById("homepage-placeholder") const homepage_placeholder = document.getElementById("homepage-placeholder")
if (hp && window.innerHeight < 600) { if (hp && window.innerHeight < 600) {
hp.style.minHeight = (heightOfEl || window.innerHeight) + 200 + "px" hp.style.minHeight = (heightOfEl || window.innerHeight) + 200 + "px"
homepage_placeholder.style.minHeight = (heightOfEl || window.innerHeight) + 350 + "px" homepage_placeholder.style.minHeight = (heightOfEl || window.innerHeight) + 350 + "px"
} }
}
}) })
function handleSlideChange() { function handleSlideChange() {

View File

@ -13,11 +13,13 @@
} }
onMount(() => { onMount(() => {
if (typeof window !== "undefined") {
interval = setInterval(() => { interval = setInterval(() => {
currentIndex = (currentIndex + 1) % $banner.length currentIndex = (currentIndex + 1) % $banner.length
}, 7000) }, 7000)
return () => clearInterval(interval) return () => clearInterval(interval)
}
}) })
</script> </script>

View File

@ -71,8 +71,9 @@
sendForm(formObj) sendForm(formObj)
} }
} }
let innerWidth = window.innerWidth
let innerWidth = window?.innerWidth || 0
if (typeof window !== "undefined") {
onMount(() => { onMount(() => {
const handleResize = () => { const handleResize = () => {
innerWidth = window.innerWidth innerWidth = window.innerWidth
@ -85,6 +86,7 @@
window.removeEventListener("resize", handleResize) window.removeEventListener("resize", handleResize)
} }
}) })
}
</script> </script>
{#if formSend} {#if formSend}

View File

@ -47,6 +47,7 @@
} }
onMount(() => { onMount(() => {
if (typeof window !== "undefined") {
const inputEl = document.querySelector(".svelte-select input") const inputEl = document.querySelector(".svelte-select input")
if (inputEl) { if (inputEl) {
inputEl.addEventListener("input", handleInputChange) inputEl.addEventListener("input", handleInputChange)
@ -56,6 +57,7 @@
inputEl.removeEventListener("input", handleInputChange) inputEl.removeEventListener("input", handleInputChange)
} }
} }
}
}) })
$: if (!valueStorage) { $: if (!valueStorage) {
valueStorage = [] valueStorage = []

View File

@ -50,7 +50,7 @@
<div class="image-container"> <div class="image-container">
<img <img
src="{`${apiBaseURL}content/${siteId}/${image.image?.src}?filter=${ src="{`${apiBaseURL}content/${siteId}/${image.image?.src}?filter=${
window.innerWidth > 500 ? 'xl' : 'm' window?.innerWidth > 500 ? 'xl' : 'm'
}`}" }`}"
alt="Bild" alt="Bild"
/> />
@ -62,7 +62,7 @@
{:else if image} {:else if image}
<div class="image-container single flex"> <div class="image-container single flex">
<img <img
src="{`${apiBaseURL}content/${siteId}/${image.image?.src}?filter=${window.innerWidth > 500 ? 'xl' : 'm'}`}" src="{`${apiBaseURL}content/${siteId}/${image.image?.src}?filter=${window?.innerWidth > 500 ? 'xl' : 'm'}`}"
alt="Bild" alt="Bild"
/> />
</div> </div>

View File

@ -22,7 +22,7 @@
<div class="img-container"> <div class="img-container">
<img <img
src="{`${apiBaseURL}content/${siteId}/${col.image?.src}?filter=${ src="{`${apiBaseURL}content/${siteId}/${col.image?.src}?filter=${
window.innerWidth > 500 ? 'xl' : 'm' window?.innerWidth > 500 ? 'xl' : 'm'
}`}" }`}"
alt="img" alt="img"
/> />

View File

@ -9,7 +9,7 @@
<div class="imgContainer"> <div class="imgContainer">
<img <img
src="{`${apiBaseURL}content/${siteId}/${col.mainPicture?.src}?filter=${ src="{`${apiBaseURL}content/${siteId}/${col.mainPicture?.src}?filter=${
window.innerWidth > 500 ? 'xl' : 'm' window?.innerWidth > 500 ? 'xl' : 'm'
}`}" }`}"
alt="img" alt="img"
/> />

View File

@ -48,7 +48,7 @@
<div class="img-container"> <div class="img-container">
<img <img
src="{`${apiBaseURL}content/${siteId}/${product.image?.src}?filter=${ src="{`${apiBaseURL}content/${siteId}/${product.image?.src}?filter=${
window.innerWidth > 500 ? 'xl' : 'm' window?.innerWidth > 500 ? 'xl' : 'm'
}`}" }`}"
alt="img" alt="img"
/> />

View File

@ -13,7 +13,7 @@
// Jump down by 100vh // Jump down by 100vh
window.scrollTo({ top: window.innerHeight, behavior: "smooth" }) window.scrollTo({ top: window.innerHeight, behavior: "smooth" })
} }
if (typeof window !== "undefined") {
onMount(() => { onMount(() => {
// Attach scroll event listener when component is mounted // Attach scroll event listener when component is mounted
window.addEventListener("scroll", checkScroll) window.addEventListener("scroll", checkScroll)
@ -23,12 +23,15 @@
// Remove scroll event listener when component is destroyed // Remove scroll event listener when component is destroyed
window.removeEventListener("scroll", checkScroll) window.removeEventListener("scroll", checkScroll)
}) })
}
let force = true let force = true
if (typeof window !== "undefined") {
setInterval(() => { setInterval(() => {
if (location.pathname != "/") { if (location.pathname != "/") {
force = false force = false
} else force = true } else force = true
}, 1000) }, 1000)
}
$: { $: {
/* if ($rerender) { /* if ($rerender) {
if (location.pathname != "/") { if (location.pathname != "/") {

View File

@ -12,7 +12,7 @@
// Scroll smoothly to the top // Scroll smoothly to the top
window.scrollTo({ top: 0, behavior: "smooth" }) window.scrollTo({ top: 0, behavior: "smooth" })
} }
if (typeof window !== "undefined") {
onMount(() => { onMount(() => {
// Attach scroll event listener when component is mounted // Attach scroll event listener when component is mounted
window.addEventListener("scroll", checkScroll) window.addEventListener("scroll", checkScroll)
@ -22,6 +22,7 @@
// Remove scroll event listener when component is destroyed // Remove scroll event listener when component is destroyed
window.removeEventListener("scroll", checkScroll) window.removeEventListener("scroll", checkScroll)
}) })
}
</script> </script>
{#if showButton} {#if showButton}

View File

@ -6,7 +6,7 @@
</script> </script>
<main class="teaser"> <main class="teaser">
{#if index % 2 == 0 || window.innerWidth < 1023} {#if index % 2 == 0 || window?.innerWidth < 1023}
<Image siteId="{site?.id}" siteImages="{site?.teaserImages || []}" /> <Image siteId="{site?.id}" siteImages="{site?.teaserImages || []}" />
{/if} {/if}
<div class="content"> <div class="content">
@ -14,7 +14,7 @@
<p>{site?.teaserDescription}</p> <p>{site?.teaserDescription}</p>
<button on:click="{() => navigate(site.path)}">MEHR</button> <button on:click="{() => navigate(site.path)}">MEHR</button>
</div> </div>
{#if index % 2 == 1 && window.innerWidth > 1023} {#if index % 2 == 1 && window?.innerWidth > 1023}
<Image siteId="{site?.id}" siteImages="{site?.teaserImages || []}" /> <Image siteId="{site?.id}" siteImages="{site?.teaserImages || []}" />
{/if} {/if}
</main> </main>

View File

@ -1,5 +1,10 @@
<script> <script>
import { navigate } from "svelte-routing" import { navigate } from "svelte-routing"
// set 404 for ssr
if (typeof window === "undefined") {
// @ts-ignore
if (context) context.is404 = true
}
</script> </script>
<svelte:head> <svelte:head>

View File

@ -9,8 +9,10 @@
"scripts": { "scripts": {
"validate": "svelte-check && tsc --noEmit", "validate": "svelte-check && tsc --noEmit",
"dev": "node scripts/esbuild-wrapper.js watch", "dev": "node scripts/esbuild-wrapper.js watch",
"start": "NAMESPACE=renz_shop node scripts/esbuild-wrapper.js start", "start": "node scripts/esbuild-wrapper.js start",
"start:ssr": "SSR=1 node scripts/esbuild-wrapper.js start",
"build": "node scripts/esbuild-wrapper.js build", "build": "node scripts/esbuild-wrapper.js build",
"build:admin": "node scripts/esbuild-wrapper.js build esbuild.config.admin.js",
"build:legacy": "node scripts/esbuild-wrapper.js build esbuild.config.legacy.js && babel _temp/index.js -o _temp/index.babeled.js && esbuild _temp/index.babeled.js --outfile=frontend/dist/index.es5.js --target=es5 --bundle --minify --sourcemap", "build:legacy": "node scripts/esbuild-wrapper.js build esbuild.config.legacy.js && babel _temp/index.js -o _temp/index.babeled.js && esbuild _temp/index.babeled.js --outfile=frontend/dist/index.es5.js --target=es5 --bundle --minify --sourcemap",
"build:server": "node scripts/esbuild-wrapper.js build esbuild.config.server.js && babel _temp/app.server.js -o _temp/app.server.babeled.js && esbuild _temp/app.server.babeled.js --outfile=api/hooks/lib/app.server.js --target=es5 --bundle --sourcemap --platform=node", "build:server": "node scripts/esbuild-wrapper.js build esbuild.config.server.js && babel _temp/app.server.js -o _temp/app.server.babeled.js && esbuild _temp/app.server.babeled.js --outfile=api/hooks/lib/app.server.js --target=es5 --bundle --sourcemap --platform=node",
"build:test": "node scripts/esbuild-wrapper.js build esbuild.config.test.js && babel --config-file ./babel.config.test.json _temp/hook.test.js -o _temp/hook.test.babeled.js && esbuild _temp/hook.test.babeled.js --outfile=api/hooks/lib/hook.test.js --target=es5 --bundle --sourcemap --platform=node", "build:test": "node scripts/esbuild-wrapper.js build esbuild.config.test.js && babel --config-file ./babel.config.test.json _temp/hook.test.js -o _temp/hook.test.babeled.js && esbuild _temp/hook.test.babeled.js --outfile=api/hooks/lib/hook.test.js --target=es5 --bundle --sourcemap --platform=node",