diff --git a/src/app/archives/page.tsx b/src/app/archives/page.tsx index 2405243..715ea26 100644 --- a/src/app/archives/page.tsx +++ b/src/app/archives/page.tsx @@ -1,4 +1,4 @@ -import { headers } from 'next/headers' +import { headers } from 'next/headers'; import Renderer from './renderer'; import { getArchives } from '../../api/archives'; diff --git a/src/app/feeds/index.xml.tsx b/src/app/feeds/index.xml.tsx deleted file mode 100644 index cdf01f8..0000000 --- a/src/app/feeds/index.xml.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { Feed } from '../../models/feed'; -import { getFeed } from '../../api/feed'; -import { generateFeedsString } from '../../services/feeds'; -import { url } from '../../../config'; -import { getRequestContext } from '../../utils/requestContext'; - -const SitemapXml = () => null; - -export async function getServerSideProps(ctx: any) { - const response: Response = await getFeed(getRequestContext(ctx.req)) - ctx.res.statusCode = response.status; - - let feedResponses = null; - if (response.status !== 200) { - return { - props: { - statusCode: 404 - } - } - } - feedResponses = await response.json() as Array; - const feeds = feedResponses.map(feed => { - return { - title: feed.title, - link: feed.link, - id: feed.id, - published: feed.published, - updated: feed.updated - } - }) as Array; - - const feedXmlString = await generateFeedsString(url, feeds); - ctx.res.setHeader("Content-Type", "text/xml"); - ctx.res.write(feedXmlString); - ctx.res.end(); - - return { - props: {} - } -} - -export default SitemapXml; diff --git a/src/app/feeds/index.xml/route.ts b/src/app/feeds/index.xml/route.ts new file mode 100644 index 0000000..628d4f3 --- /dev/null +++ b/src/app/feeds/index.xml/route.ts @@ -0,0 +1,34 @@ +import { headers } from 'next/headers'; + +import { Feed } from '../../../models/feed'; +import { getFeed } from '../../../api/feed'; +import { generateFeedsString } from '../../../services/feeds'; +import { url } from '../../../../config'; +import { getRequestContext } from '../../../utils/requestContext'; + +//export async function get(ctx: any) { +export async function GET() { + const response: Response = await getFeed(getRequestContext(headers())); + // ctx.res.statusCode = response.status; // TODO + + if (response.status !== 200) { + return new Response(new Blob(), { status: 404 }); + } + let feedResponses = await response.json() as Array; + const feeds = feedResponses.map(feed => { + return { + title: feed.title, + link: feed.link, + id: feed.id, + published: feed.published, + updated: feed.updated + } + }) as Array; + + const feedXmlString = await generateFeedsString(url, feeds); + return new Response(feedXmlString, { + headers: { + "Content-Type": "text/xml", + }, + }); +} diff --git a/src/app/sitemap.xml.tsx b/src/app/sitemap.xml.tsx deleted file mode 100644 index d07e0da..0000000 --- a/src/app/sitemap.xml.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { Sitemap } from '../models/sitemap'; -import { getSitemap } from '../api/sitemap'; -import { generateSitemapString } from '../services/sitemap'; -import { url } from '../../config'; -import { getRequestContext } from '../utils/requestContext'; - -const SitemapXml = () => null; - -export async function getServerSideProps(ctx: any) { - const response: Response = await getSitemap(getRequestContext(ctx.req)) - ctx.res.statusCode = response.status; - - let sitemapResponse = null; - if (response.status !== 200) { - return { - props: { - statusCode: 404 - } - } - } - sitemapResponse = await response.json() as Array; - const sitemap = sitemapResponse.map(sitemap => { - return { - loc: sitemap.loc, - lastMod: sitemap.lastMod - } - }) as Array; - - const sitemapXmlString = await generateSitemapString(url, sitemap); - ctx.res.setHeader("Content-Type", "text/xml"); - ctx.res.write(sitemapXmlString); - ctx.res.end(); - - return { - props: {} - } -} - -export default SitemapXml; diff --git a/src/app/sitemap.xml/route.ts b/src/app/sitemap.xml/route.ts new file mode 100644 index 0000000..662bf69 --- /dev/null +++ b/src/app/sitemap.xml/route.ts @@ -0,0 +1,38 @@ +import { headers } from 'next/headers'; + +import { Sitemap } from '../../models/sitemap'; +import { getSitemap } from '../../api/sitemap'; +import { generateSitemapString } from '../../services/sitemap'; +import { url } from '../../../config'; +import { getRequestContext } from '../../utils/requestContext'; + +export async function GET() { + const response: Response = await getSitemap(getRequestContext(headers())); + + /* TODO + ctx.res.statusCode = response.status; + + let sitemapResponse = null; + if (response.status !== 200) { + return { + props: { + statusCode: 404 + } + } + } + */ + let sitemapResponse = await response.json() as Array; + const sitemap = sitemapResponse.map(sitemap => { + return { + loc: sitemap.loc, + lastMod: sitemap.lastMod + } + }) as Array; + + const sitemapXmlString = await generateSitemapString(url, sitemap); + return new Response(sitemapXmlString, { + headers: { + "Content-Type": "text/xml", + }, + }); +}