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 // https://astro.build/config
export default defineConfig({ export default defineConfig({
output: "hybrid", output: "server",
adapter: node({ adapter: node({
mode: "standalone", mode: "standalone",
}), }),

View File

@ -1,4 +1,6 @@
--- ---
export const prerender = true;
import SinglePage from "../layouts/SinglePage.astro"; import SinglePage from "../layouts/SinglePage.astro";
import AboutModule from "./AboutModule.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`}> <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 SingleCompositionCard from "./SingleCompositionCard.astro";
import { Separator } from "./ui/separator"; import { Separator } from "./ui/separator";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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