nextjs Data List
- NEXT.JS 기본개념
- NEXT.JS 설치
- NEXT.JS 실행방법
- NEXT.JS 파일 및 구조
- NEXT.JS 데이터 가져오기
- NEXT.JS API 쿼리데이터 생성
- NEXT.JS Components
- NEXT.JS page.js 파라미터 처리
- NEXT.JS app router 방식 client ip 주소 가져오는 방법
- NEXT.JS monaco-editor 사용방법
- NEXT.JS react-quill 사용방법
- NEXT.JS app router 방식 rss feed.xml 간단하게 설정 방법
- NEXT.JS app router 방식 sitemap.xml 간단하게 설정 방법
NEXT.JS app router 방식 rss feed.xml 간단하게 설정 방법
2024-02-29 10:57:00
/ 목차 /
- rss 설치
- 파일 생성
- route.ts 소스
- url 테스트
rss 설치
command - npm install rss - npm install @types/rss
타입스크립트 사용시 @types/rss 설치 하셔야 합니다.파일 생성
- 폴더생성 src/app/feed.xml/route.ts 루트경로에 src/app/feed.xml 폴더를 생성하고 그안에 route.ts 파일을 생성 합니다.route.ts 소스
code import RSS from "rss" async function getFeedData() { return 'data' } export async function GET() { const feed = new RSS({ title: 'datadeveloper', description: "developer blog", generator: 'RSS for Node and Next.js', feed_url: 'https://www.datadeveloper.kr/feed.xml', site_url: 'https://www.datadeveloper.kr', copyright: `Copyright ${new Date().getFullYear().toString()}`, language: 'ko-KR', pubDate: new Date().toUTCString(), ttl: 60, }); const allPosts = await getFeedData(); if (allPosts) { allPosts.map((post:any) => { feed.item({ title: post.제목, description: post.내용, url: post.주소, date: post.등록일자 }); }); } return new Response(feed.xml({ indent: true }), { headers: { 'Content-Type': 'application/xml; charset=utf-8', }, }); }
getFeedData() 해당 함수안에 데이터만 가져와주는 코드만 작성해 주시면 됩니다.url 테스트
localhost:3000/feed.xml
Comment