File tree Expand file tree Collapse file tree 17 files changed +1223
-89
lines changed Expand file tree Collapse file tree 17 files changed +1223
-89
lines changed Original file line number Diff line number Diff line change 1+ MONGODB = ' mongodb://127.0.0.1:27017/ryugen'
2+ APP_URL = ' http://localhost:3000'
Original file line number Diff line number Diff line change 1111 "dependencies" : {
1212 "eslint" : " 8.42.0" ,
1313 "eslint-config-next" : " 13.4.5" ,
14+ "mongoose" : " 6.11.1" ,
1415 "next" : " 13.4.5" ,
16+ "next-auth" : " ^4.22.1" ,
1517 "react" : " 18.2.0" ,
1618 "react-dom" : " 18.2.0" ,
1719 "swr" : " ^2.1.5"
Original file line number Diff line number Diff line change 1+ import connect from "@/utils/db" ;
2+ import Post from "@/models/Post" ;
3+ import { NextResponse } from "next/server" ;
4+
5+ export const GET = async ( request , { params} ) => {
6+ const { id} = params ;
7+ try {
8+ await connect ( ) ;
9+ const post = await Post . findById ( id ) ;
10+ return new NextResponse ( JSON . stringify ( post ) , { status : 200 } ) ;
11+ } catch ( err ) {
12+ return new NextResponse ( "Database Error" , { status : 500 } ) ;
13+ }
14+ }
15+
Original file line number Diff line number Diff line change 1+ import connect from "@/utils/db" ;
2+ import Post from "@/models/Post" ;
3+ import { NextResponse } from "next/server" ;
4+
5+ export const GET = async ( request ) => {
6+ try {
7+ await connect ( ) ;
8+ const posts = await Post . find ( ) ;
9+ return new NextResponse ( JSON . stringify ( posts ) , { status : 200 } ) ;
10+ } catch ( err ) {
11+ return new NextResponse ( "Database Error" , { status : 500 } ) ;
12+ }
13+ }
14+
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ import styles from './page.module.css'
3+ import Image from 'next/image'
4+ import { notFound } from 'next/navigation'
5+
6+ async function getData ( id ) {
7+ const res = await fetch ( `${ process . env . APP_URL } /api/posts/${ id } ` , {
8+ cache :'no-store'
9+ } )
10+ if ( ! res . ok ) {
11+ return notFound ( )
12+ }
13+
14+ return res . json ( )
15+ }
16+
17+
18+ export async function generateMetadata ( { params} ) {
19+ const post = await getData ( params . id ) ;
20+ return {
21+ title :post . title ,
22+ description :post . desc
23+ } ;
24+ }
25+
26+ const Post = async ( { params} ) => {
27+ const data = await getData ( params . id ) ;
28+ return (
29+ < div className = { styles . container } >
30+ < div className = { styles . top } >
31+ < div className = { styles . info } >
32+ < h1 className = { styles . title } > { data . title } </ h1 >
33+ < p className = { styles . desc } >
34+ {
35+ data . desc
36+ }
37+ </ p >
38+ < div className = { styles . author } >
39+ < Image
40+ src = 'https://i.pinimg.com/564x/33/f7/f9/33f7f9739a50e708034b987544d2130d.jpg'
41+ width = { 40 }
42+ height = { 40 }
43+ alt = 'author_img'
44+ className = { styles . avatar }
45+ />
46+ < span className = { styles . username } > { data . username } </ span >
47+ </ div >
48+ </ div >
49+ < div className = { styles . imgContainer } >
50+ < Image
51+ src = { data . img }
52+ fill = { true }
53+ className = { styles . img }
54+ alt = 'image post'
55+ />
56+ </ div >
57+ </ div >
58+ < div className = { styles . content } >
59+ { data . content }
60+ </ div >
61+ </ div >
62+ )
63+ }
64+
65+ export default Post
File renamed without changes.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // "use client"
2+
13import React from 'react'
24import styles from './page.module.css'
35import Link from 'next/link'
46import Image from 'next/image'
57
68
79async function getData ( ) {
8- const res = await fetch ( 'https://jsonplaceholder.typicode.com/ posts' , {
10+ const res = await fetch ( ` ${ process . env . APP_URL } /api/ posts` , {
911 cache :'no-store'
1012 } )
1113 if ( ! res . ok ) {
1214 throw new Error ( 'Failed to fetch data' )
1315 }
14-
1516 return res . json ( )
1617}
1718
@@ -21,10 +22,10 @@ const Blog = async () => {
2122 < div className = { styles . mainContainer } >
2223 {
2324 data . map ( item => (
24- < Link href = { `/blog/${ item . id } ` } className = { styles . container } key = { item . id } >
25+ < Link href = { `/blog/${ item . _id } ` } className = { styles . container } key = { item . _id } >
2526 < div className = { styles . imgContainer } >
2627 < Image
27- src = 'https://i.pinimg.com/564x/7d/7a/02/7d7a02a6df18a1dfce7e5d8c74b9a7d7.jpg'
28+ src = { item . img }
2829 alt = 'image blog'
2930 width = { 400 }
3031 height = { 250 }
@@ -33,7 +34,7 @@ const Blog = async () => {
3334 </ div >
3435 < div className = { styles . content } >
3536 < h1 className = { styles . title } > { item . title } </ h1 >
36- < p className = { styles . description } > { item . body } </ p >
37+ < p className = { styles . description } > { item . desc } </ p >
3738 </ div >
3839 </ Link >
3940 ) )
Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ import Image from 'next/image';
44import Button from '@/components/button/Button' ;
55
66
7+ export const metadata = {
8+ title : 'My portofolio || contact' ,
9+ description : 'this is contact page' ,
10+ }
11+
712const Contact = ( ) => {
813 return (
914 < div className = { styles . container } >
You can’t perform that action at this time.
0 commit comments