manifest + fav icon + title page
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getRestaurant } from "../lib/getRestaurant";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const revalidate = 0;
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ name: string }> }
|
||||
) {
|
||||
try {
|
||||
const { name } = await params;
|
||||
const restaurant = await getRestaurant(name);
|
||||
|
||||
const themeColor = restaurant.menuColor || "#F4F5F9";
|
||||
const logo = restaurant.logo;
|
||||
|
||||
const icons = [];
|
||||
if (logo && logo.trim() !== "") {
|
||||
icons.push(
|
||||
{
|
||||
src: logo,
|
||||
sizes: "192x192",
|
||||
type: "image/png",
|
||||
purpose: "any",
|
||||
},
|
||||
{
|
||||
src: logo,
|
||||
sizes: "512x512",
|
||||
type: "image/png",
|
||||
purpose: "any",
|
||||
}
|
||||
);
|
||||
} else {
|
||||
icons.push(
|
||||
{
|
||||
src: "/icons/web-app-manifest-192x192.png",
|
||||
sizes: "192x192",
|
||||
type: "image/png",
|
||||
purpose: "any",
|
||||
},
|
||||
{
|
||||
src: "/icons/web-app-manifest-512x512.png",
|
||||
sizes: "512x512",
|
||||
type: "image/png",
|
||||
purpose: "any",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const manifest = {
|
||||
name: restaurant.name,
|
||||
short_name: restaurant.name,
|
||||
description: restaurant.description || `منوی ${restaurant.name}`,
|
||||
start_url: `/${name}`,
|
||||
scope: `/${name}`,
|
||||
id: `/${name}`,
|
||||
display: "standalone",
|
||||
display_override: ["fullscreen", "minimal-ui", "browser"],
|
||||
background_color: "#F4F5F9",
|
||||
theme_color: themeColor,
|
||||
orientation: "portrait",
|
||||
dir: "rtl",
|
||||
lang: "fa-IR",
|
||||
icons,
|
||||
};
|
||||
|
||||
return NextResponse.json(manifest, {
|
||||
headers: {
|
||||
"Content-Type": "application/manifest+json",
|
||||
"Cache-Control":
|
||||
"no-store, no-cache, must-revalidate, proxy-revalidate",
|
||||
Pragma: "no-cache",
|
||||
Expires: "0",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === "RESTAURANT_NOT_FOUND") {
|
||||
return new NextResponse("Restaurant not found", { status: 404 });
|
||||
}
|
||||
|
||||
return new NextResponse("Internal Server Error", { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user