Merged in feat/warmup-cache-function (pull request #1581)
Feat/warmup cache function * WIP * Fix warmup for all languages * Cleanup * Added env flag so we can disable warmup * Changed time to 04.00 UTC since backend updates their data at 03.00 UTC * Add return statements * Merge branch 'master' into feat/warmup-cache-function Approved-by: Anton Gunnarsson
This commit is contained in:
41
apps/scandic-web/app/api/hoteldata/route.ts
Normal file
41
apps/scandic-web/app/api/hoteldata/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import { languageSchema } from "@/utils/languages"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
if (!env.ENABLE_WARMUP_HOTEL) {
|
||||
console.log("[WARMUP] Warmup hotel data is disabled")
|
||||
return NextResponse.json(
|
||||
{ message: "Warmup hotel data is disabled" },
|
||||
{ status: 200 }
|
||||
)
|
||||
}
|
||||
|
||||
try {
|
||||
const searchParams = request.nextUrl.searchParams
|
||||
const lang = searchParams.get("lang")
|
||||
const parsedLang = languageSchema.safeParse(lang)
|
||||
|
||||
if (!parsedLang.success) {
|
||||
throw new Error("[WARMUP] Invalid language provided")
|
||||
}
|
||||
|
||||
const hotels = await serverClient().hotel.hotels.getAllHotels.get({
|
||||
lang: parsedLang.data,
|
||||
})
|
||||
return NextResponse.json(hotels)
|
||||
} catch (error) {
|
||||
console.error("[WARMUP] error", error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: "Failed to fetch all hotels",
|
||||
},
|
||||
{ status: 500, statusText: "Internal Server Error" }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user