mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 02:15:01 +00:00
Sitemap and cors for nextjs
This commit is contained in:
parent
5a3b08e621
commit
9ccaa396dc
4 changed files with 49 additions and 1 deletions
|
|
@ -15,6 +15,12 @@ const { handleRequest } = createYoga<NextContext>({
|
|||
fetchAPI: { Response },
|
||||
|
||||
graphiql: true,
|
||||
|
||||
cors: {
|
||||
origin: "*", // Allow all origins for simplicity, adjust as needed
|
||||
methods: ["GET", "POST", "OPTIONS"],
|
||||
credentials: true,
|
||||
},
|
||||
});
|
||||
|
||||
export {
|
||||
|
|
|
|||
34
packages/skin-database/app/sitemap.ts
Normal file
34
packages/skin-database/app/sitemap.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import type { MetadataRoute } from "next";
|
||||
import * as Skins from "../data/skins";
|
||||
|
||||
// Google's limit is 50,000 URLs per sitemap
|
||||
const PAGE_SIZE = 50000;
|
||||
|
||||
const BASE_URL = "https://skins.webamp.org";
|
||||
|
||||
export async function generateSitemaps(): Promise<{ id: number }[]> {
|
||||
const count = await Skins.getClassicSkinCount();
|
||||
const maps: { id: number }[] = [];
|
||||
for (let i = 0; i < Math.ceil(count / PAGE_SIZE); i++) {
|
||||
maps.push({ id: i });
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
export default async function sitemap({
|
||||
id,
|
||||
}: {
|
||||
id: string;
|
||||
}): Promise<MetadataRoute.Sitemap> {
|
||||
const md5s = await Skins.getAllClassicSkins();
|
||||
const skinUrls = md5s.map(({ md5, fileName }) => `skin/${md5}/${fileName}`);
|
||||
const urls = ["/about", "/", "/upload", ...skinUrls];
|
||||
const slice = urls.slice(
|
||||
parseInt(id, 10) * PAGE_SIZE,
|
||||
(parseInt(id, 10) + 1) * PAGE_SIZE
|
||||
);
|
||||
return slice.map((url) => ({
|
||||
url: `${BASE_URL}${url}`,
|
||||
changeFrequency: "monthly",
|
||||
}));
|
||||
}
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
import { parse } from "url";
|
||||
import next from "next";
|
||||
import { createApp } from "./api/app";
|
||||
|
|
|
|||
|
|
@ -15486,11 +15486,16 @@ graphql-yoga@^5.10.10:
|
|||
lru-cache "^10.0.0"
|
||||
tslib "^2.8.1"
|
||||
|
||||
graphql@16.8.1, graphql@^16.8.1, graphql@^16.9.0:
|
||||
graphql@^16.8.1:
|
||||
version "16.8.1"
|
||||
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.8.1.tgz#1930a965bef1170603702acdb68aedd3f3cf6f07"
|
||||
integrity sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==
|
||||
|
||||
graphql@^16.9.0:
|
||||
version "16.11.0"
|
||||
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.11.0.tgz#96d17f66370678027fdf59b2d4c20b4efaa8a633"
|
||||
integrity sha512-mS1lbMsxgQj6hge1XZ6p7GPhbrtFwUFYi3wRzXAC/FmYnyXMTvvI3td3rjmQ2u8ewXueaSvRPWaEcgVVOT9Jnw==
|
||||
|
||||
grats@^0.0.31:
|
||||
version "0.0.31"
|
||||
resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.31.tgz#f094786584a0f2fb345b38e6c37330d3f4f391cd"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue