feat: cms cache
This commit is contained in:
@@ -9,10 +9,9 @@ import {
|
||||
import { env } from "@/env/server"
|
||||
import { internalServerError, notFound } from "@/server/errors/next"
|
||||
|
||||
import { resolve as resolveEntry } from "@/utils/entry"
|
||||
import { findLang } from "@/utils/languages"
|
||||
|
||||
import { getDefaultRequestHeaders } from "./utils"
|
||||
import { fetchAndCacheEntry, getDefaultRequestHeaders } from "./utils"
|
||||
|
||||
import type { NextMiddleware } from "next/server"
|
||||
|
||||
@@ -40,8 +39,11 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
}
|
||||
|
||||
const pathNameWithoutLang = nextUrl.pathname.replace(`/${lang}`, "")
|
||||
const { uid, contentType } = await resolveEntry(pathNameWithoutLang, lang)
|
||||
if (!uid) {
|
||||
const { uid, contentType } = await fetchAndCacheEntry(
|
||||
pathNameWithoutLang,
|
||||
lang
|
||||
)
|
||||
if (!uid || !contentType) {
|
||||
throw notFound(
|
||||
`Unable to resolve CMS entry for locale "${lang}": ${pathNameWithoutLang}`
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user