Skip to content

Commit 8ccd09e

Browse files
authored
use ISR
1 parent 5245653 commit 8ccd09e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

pages/drafts.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from "react";
2-
import { GetServerSideProps } from "next";
2+
import type { GetStaticProps } from "next";
33
import Layout from "../components/Layout";
44
import Post, { PostProps } from "../components/Post";
55
import { useSession, getSession } from "next-auth/react";
66
import prisma from '../lib/prisma'
77

88

9-
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
9+
export const getStaticProps: GetStaticProps = async ({ req, res }) => {
1010
const session = await getSession({ req });
1111
if (!session) {
1212
res.statusCode = 403;
@@ -26,6 +26,7 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
2626
});
2727
return {
2828
props: { drafts },
29+
revalidate: 10
2930
};
3031
};
3132

pages/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
2-
import { GetServerSideProps } from "next";
2+
import type { GetStaticProps } from "next";
33
import Layout from "../components/Layout";
44
import Post, { PostProps } from "../components/Post";
55
import prisma from '../lib/prisma'
66

7-
export const getServerSideProps: GetServerSideProps = async () => {
7+
export const getStaticProps: GetStaticProps = async () => {
88
const feed = await prisma.post.findMany({
99
where: {
1010
published: true,
@@ -19,6 +19,7 @@ export const getServerSideProps: GetServerSideProps = async () => {
1919
});
2020
return {
2121
props: { feed },
22+
revalidate: 10,
2223
};
2324
};
2425

pages/p/[id].tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import React from "react";
2-
import { GetServerSideProps } from "next";
2+
import type { GetStaticProps } from "next";
33
import ReactMarkdown from "react-markdown";
44
import Layout from "../../components/Layout";
55
import Router from "next/router";
66
import { PostProps } from "../../components/Post";
77
import prisma from '../../lib/prisma'
88
import { useSession } from "next-auth/react";
99

10-
11-
export const getServerSideProps: GetServerSideProps = async ({ params }) => {
10+
export const getStaticProps: GetStaticProps = async ({ params }) => {
1211
const post = await prisma.post.findUnique({
1312
where: {
1413
id: String(params?.id) ,
@@ -21,6 +20,7 @@ export const getServerSideProps: GetServerSideProps = async ({ params }) => {
2120
});
2221
return {
2322
props: post,
23+
revalidate: 10,
2424
};
2525
};
2626

0 commit comments

Comments
 (0)