Enabled SSR with pre-renders

- Enable server output mode
- Pre-render for (almost) every .astro file
- Fixed custom middleware
This commit is contained in:
Cyril Šebek 2024-07-08 23:01:44 +02:00
parent 397ba05c7c
commit 7a71a66dc7
Signed by: blboun3
SSH Key Fingerprint: SHA256:n9dMtOPzgsD+CCerUJslEnU2dzVanbaIv0XDQVRVjeg
14 changed files with 25 additions and 15 deletions

View File

@ -9,7 +9,7 @@ import react from "@astrojs/react";
// https://astro.build/config
export default defineConfig({
output: "hybrid",
output: "server",
adapter: node({
mode: "standalone",
}),

View File

@ -1,4 +1,6 @@
---
export const prerender = true;
import SinglePage from "../layouts/SinglePage.astro";
import AboutModule from "./AboutModule.astro";

View File

@ -1,5 +1,6 @@
---
const { row, flipped, image, alt } = Astro.props;
---
export const prerender = true;
const { row, flipped, image } = Astro.props;
---
<div class={`rows-start-${row} row-span-1 h-full w-full`}>

View File

@ -1,4 +1,5 @@
---
export const prerender = true;
import SingleCompositionCard from "./SingleCompositionCard.astro";
import { Separator } from "./ui/separator";

View File

@ -1,4 +1,5 @@
---
export const prerender = true;
import { ContactButton } from "./ContactButton";
---

View File

@ -1,4 +1,5 @@
---
export const prerender = true;
import SinglePage from "../layouts/SinglePage.astro";
import { getLangFromUrl, useTranslations } from "../i18n/utils";

View File

@ -1,4 +1,5 @@
---
export const prerender = true;
import { ThemeSelector } from "./ThemeSelector"
import NavbarSkeleton from "./NavbarSkeleton.astro";
import { LangSwitcher } from "./LangSwitcher";

View File

@ -1,3 +1,6 @@
---
export const prerender = true;
---
<nav class="w-full flex justify-center">
<div class="fixed w-full top-0 z-50 bg-bkgNavbar/70 shadow-md rounded-b-md backdrop-blur-lg">
<div

View File

@ -1,6 +1,6 @@
---
import SinglePostCard from "./SinglePostCard.astro";
export const prerender = true;
const { filteredPosts } = Astro.props;
---

View File

@ -1,6 +1,7 @@
---
import SinglePage from "../layouts/SinglePage.astro";
import { ShowcaseTabs } from "./ShowcaseTabs.jsx";
export const prerender = true;
---
<SinglePage>

View File

@ -1,4 +1,5 @@
---
export const prerender = true;
import {
Card,
CardContent,

View File

@ -1,5 +1,5 @@
---
import { Image } from "astro:assets";
export const prerender = true;
import {
Card,
CardContent,

View File

@ -1,24 +1,24 @@
import { defineMiddleware, sequence } from "astro:middleware";
import { middleware } from "astro:i18n"; // Astro's own i18n routing config
export const prerender = false
const langs = ["en", "de", "cs", "fr"]
export const userMiddleware = defineMiddleware(async (ctx, next) => {
// this response might come from Astro's i18n middleware, and it might return a 404
const response = await next();
export const userMiddleware = defineMiddleware((ctx, next) => {
const exceptions = ["/api", "/public"]
// If path is in exceptions (i.e. api or public) return default middleware to handle it
if (exceptions.includes(ctx.url.pathname) ) {
return response
return next();
// If no lang is set => set to english (some pages are language-les exceptions)
} else if ( !langs.some(item => ctx.url.href.includes(item)) ) {
return Response.redirect(`${ctx.url.protocol}${ctx.url.host}/en${ctx.url.pathname}`);
} else {
return response;
return next();
}
});

View File

@ -1,15 +1,13 @@
---
export const prerender = true;
import MainLayout from "../layouts/MainLayout.astro";
import SinglePage from "../layouts/SinglePage.astro";
---
<MainLayout
title="Error 404"
,
description="This page doesn't exists"
,
lang="en"
>
lang="en">
<SinglePage>
<div class="text-2xl text-center h-[80vh] grid place-content-center">
<p class="text-accent">It looks like this page doesn't exists!</p>