Skip to content

Commit

Permalink
Merge pull request #35 from hamster1963/force-static
Browse files Browse the repository at this point in the history
Set main page to force-static for cache and CDN
  • Loading branch information
hamster1963 authored Sep 30, 2024
2 parents 4671ee3 + e54ed36 commit 7d5a2dd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/[locale]/(main)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { unstable_setRequestLocale } from "next-intl/server";
import ServerList from "../../../components/ServerList";
import ServerOverview from "../../../components/ServerOverview";

export default function Home() {
export default function Home({
params: { locale },
}: {
params: { locale: string };
}) {
unstable_setRequestLocale(locale);
return (
<div className="mx-auto grid w-full max-w-5xl gap-4 md:gap-6">
<ServerOverview />
Expand Down
10 changes: 10 additions & 0 deletions app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { Inter as FontSans } from "next/font/google";
import { ThemeProvider } from "next-themes";
import { Viewport } from "next";
import { cn } from "@/lib/utils";
import { locales } from "@/i18n-metadata";
import { unstable_setRequestLocale } from "next-intl/server";

const fontSans = FontSans({
subsets: ["latin"],
Expand All @@ -35,13 +37,21 @@ export const viewport: Viewport = {
userScalable: false,
};

export const dynamic = "force-static";

export async function generateStaticParams() {
return locales.map((locale) => ({ locale }));
}

export default function LocaleLayout({
children,
params: { locale },
}: {
children: React.ReactNode;
params: { locale: string };
}) {
unstable_setRequestLocale(locale);

const messages = useMessages();
return (
<html lang={locale} suppressHydrationWarning>
Expand Down
13 changes: 12 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import withBundleAnalyzer from "@next/bundle-analyzer";

const bundleAnalyzer = withBundleAnalyzer({
enabled: process.env.ANALYZE === "true",
});

import createNextIntlPlugin from "next-intl/plugin";
const withNextIntl = createNextIntlPlugin();
import withPWAInit from "@ducanh2912/next-pwa";
Expand All @@ -16,5 +22,10 @@ const withPWA = withPWAInit({
const nextConfig = {
output: "standalone",
reactStrictMode: true,
logging: {
fetches: {
fullUrl: true,
},
},
};
export default withPWA(withNextIntl(nextConfig));
export default bundleAnalyzer(withPWA(withNextIntl(nextConfig)));

0 comments on commit 7d5a2dd

Please sign in to comment.