Skip to content

Commit

Permalink
op
Browse files Browse the repository at this point in the history
  • Loading branch information
SH20RAJ authored Mar 18, 2024
1 parent 3bc1db6 commit 7626eb6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/app/sitemap2/route.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// import fetch from 'isomorphic-fetch'; // Import fetch
// import { getArticlesFromDevTo } from 'someFunctions'; // Replace with your actual function to fetch articles

import { NextResponse } from "next/server";

// Mock function to fetch articles (replace this with your actual implementation)
let getArticlesFromDevTo = async () => {
const response = await fetch(
`https://dev.to/api/articles/latest/?per_page=1000&page=1`
`https://dev.to/api/articles/latest/?per_page=100&page=1`
);
const data = await response.json();
return data;
Expand All @@ -18,7 +20,7 @@ export async function GET(req) {

// Start building the XML
let xml = '<?xml version="1.0" encoding="UTF-8"?>';
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
xml += `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">`;

// Add each article URL to the sitemap
articles.forEach((article) => {
Expand All @@ -33,11 +35,17 @@ export async function GET(req) {
xml += '</urlset>';

// Set the response headers and status
return new Response(xml, {
return new NextResponse(xml, {
headers: {
'Content-Type': 'application/xml',
},
status: 200,

headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
}
});
} catch (error) {
console.error('Error generating sitemap:', error);
Expand Down

0 comments on commit 7626eb6

Please sign in to comment.