Skip to content

Commit fc5b1dc

Browse files
authored
Merge pull request #218 from rush-db/fix/isr-ssg-website
Fix/isr ssg website
2 parents 1dd2d04 + 5bbeb3e commit fc5b1dc

5 files changed

Lines changed: 81 additions & 139 deletions

File tree

website/public/sitemap-0.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
3-
<url><loc>https://rushdb.com</loc><lastmod>2025-06-29T17:25:17.632Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
4-
<url><loc>https://rushdb.com/blog</loc><lastmod>2025-06-29T17:25:17.633Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
5-
<url><loc>https://rushdb.com/pricing</loc><lastmod>2025-06-29T17:25:17.633Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
6-
<url><loc>https://rushdb.com/blog/backendless-fullstack-development-react-useform-rushdb</loc><lastmod>2025-06-29T17:25:17.633Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
7-
<url><loc>https://rushdb.com/blog/rushdb-the-zero-config-database-for-modern-apps-and-ai-solutions</loc><lastmod>2025-06-29T17:25:17.633Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
8-
<url><loc>https://rushdb.com/blog/rushdb-selfhosted-quick-setup</loc><lastmod>2025-06-29T17:25:17.633Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
3+
<url><loc>https://rushdb.com</loc><lastmod>2025-06-29T19:02:45.019Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
4+
<url><loc>https://rushdb.com/blog</loc><lastmod>2025-06-29T19:02:45.020Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
5+
<url><loc>https://rushdb.com/pricing</loc><lastmod>2025-06-29T19:02:45.020Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
6+
<url><loc>https://rushdb.com/blog/backendless-fullstack-development-react-useform-rushdb</loc><lastmod>2025-06-29T19:02:45.020Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
7+
<url><loc>https://rushdb.com/blog/rushdb-the-zero-config-database-for-modern-apps-and-ai-solutions</loc><lastmod>2025-06-29T19:02:45.020Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
8+
<url><loc>https://rushdb.com/blog/rushdb-selfhosted-quick-setup</loc><lastmod>2025-06-29T19:02:45.020Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
99
</urlset>

website/src/pages/[slug].tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { MDXRemoteSerializeResult } from 'next-mdx-remote'
22

33
import { Layout } from '~/components/Layout'
4-
import { GetStaticProps, GetStaticPaths } from 'next'
4+
import { GetServerSideProps } from 'next'
55
import { Page } from '~/sections/blog/types'
66
import { MDXPageRenderer } from '~/sections/blog/MDXRenderer'
77
import { getRemotePage } from '~/sections/blog/remote-utils'
@@ -17,8 +17,6 @@ type Params = {
1717
slug: string
1818
}
1919

20-
export const revalidate = 3600
21-
2220
export default function StaticPage({ serializedPage, data }: Props) {
2321
return (
2422
<Layout title={data.title}>
@@ -27,23 +25,14 @@ export default function StaticPage({ serializedPage, data }: Props) {
2725
)
2826
}
2927

30-
export const getStaticPaths: GetStaticPaths = async () => {
31-
// For static pages, we'll use fallback: 'blocking' to generate pages on-demand
32-
// This allows for ISR with new pages that weren't pre-built
33-
return {
34-
paths: [], // We'll generate pages on-demand
35-
fallback: 'blocking'
36-
}
37-
}
38-
39-
export const getStaticProps: GetStaticProps<Props, Params> = async ({ params }) => {
28+
export const getServerSideProps: GetServerSideProps<Props> = async ({ params }) => {
4029
if (!params?.slug) {
4130
return {
4231
notFound: true
4332
}
4433
}
4534

46-
const page = await getRemotePage(params.slug)
35+
const page = await getRemotePage(params.slug as string)
4736

4837
if (!page?.__id) {
4938
return {
@@ -62,7 +51,6 @@ export const getStaticProps: GetStaticProps<Props, Params> = async ({ params })
6251
props: {
6352
serializedPage,
6453
data: page
65-
},
66-
revalidate: 3600 // Revalidate every hour
54+
}
6755
}
6856
}

website/src/pages/blog/[slug].tsx

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MDXRemoteSerializeResult } from 'next-mdx-remote'
22
import { serialize } from 'next-mdx-remote/serialize'
33

44
import { Layout } from '~/components/Layout'
5-
import { GetStaticProps } from 'next'
5+
import { GetServerSideProps } from 'next'
66
import { LetterTypingText } from '~/components/LetterTypingText'
77
import { getRemoteBlogPost, getRemoteBlogPosts } from '~/sections/blog/remote-utils'
88
import { Post } from '~/sections/blog/types'
@@ -26,8 +26,6 @@ type Params = {
2626
slug: string
2727
}
2828

29-
export const revalidate = 3600
30-
3129
export default function PostPage({ serializedPost, data, morePosts }: Props) {
3230
const router = useRouter()
3331

@@ -71,21 +69,7 @@ export default function PostPage({ serializedPost, data, morePosts }: Props) {
7169
)
7270
}
7371

74-
export const getStaticPaths = async () => {
75-
// Get all published posts for static generation
76-
const posts = await getRemoteBlogPosts()
77-
78-
const paths = posts.map((post) => ({
79-
params: { slug: post.slug }
80-
}))
81-
82-
return {
83-
paths,
84-
fallback: 'blocking' // Enable ISR for new posts
85-
}
86-
}
87-
88-
export const getStaticProps: GetStaticProps<Props, Params> = async ({ params }) => {
72+
export const getServerSideProps: GetServerSideProps<Props> = async ({ params }) => {
8973
if (!params?.slug) {
9074
return {
9175
notFound: true
@@ -94,7 +78,10 @@ export const getStaticProps: GetStaticProps<Props, Params> = async ({ params })
9478

9579
try {
9680
// Fetch post and all posts in parallel
97-
const [post, allPosts] = await Promise.all([getRemoteBlogPost(params.slug), getRemoteBlogPosts()])
81+
const [post, allPosts] = await Promise.all([
82+
getRemoteBlogPost(params.slug as string),
83+
getRemoteBlogPosts()
84+
])
9885

9986
if (!post?.__id) {
10087
return {
@@ -118,11 +105,10 @@ export const getStaticProps: GetStaticProps<Props, Params> = async ({ params })
118105
serializedPost,
119106
data: post,
120107
morePosts
121-
},
122-
revalidate: 3600 // Revalidate every hour
108+
}
123109
}
124110
} catch (error) {
125-
console.error('Error in getStaticProps:', error)
111+
console.error('Error in getServerSideProps:', error)
126112
return {
127113
notFound: true
128114
}

website/src/pages/blog/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames'
2-
import { GetStaticProps } from 'next'
2+
import { GetServerSideProps } from 'next'
33

44
import { Layout } from '~/components/Layout'
55
import { LetterTypingText } from '~/components/LetterTypingText'
@@ -9,8 +9,6 @@ import { getRemoteBlogPosts } from '~/sections/blog/remote-utils'
99

1010
type Props = { posts: Array<Post['data']> }
1111

12-
export const revalidate = 3600
13-
1412
export default function Index({ posts }: Props) {
1513
return (
1614
<Layout className="container">
@@ -43,13 +41,12 @@ export default function Index({ posts }: Props) {
4341
)
4442
}
4543

46-
export const getStaticProps: GetStaticProps<Props> = async () => {
44+
export const getServerSideProps: GetServerSideProps<Props> = async () => {
4745
const posts = await getRemoteBlogPosts()
4846

4947
return {
5048
props: {
5149
posts
52-
},
53-
revalidate: 3600 // Revalidate every hour (3600 seconds)
50+
}
5451
}
5552
}
Lines changed: 60 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,78 @@
11
import { PostModel, PageModel } from '~/models'
22
import { Post, Page } from './types'
3-
import { unstable_cache } from 'next/cache'
43

5-
// Function to get all blog posts with Next.js caching
6-
export const getRemoteBlogPosts = unstable_cache(
7-
async (): Promise<Post['data'][]> => {
8-
try {
9-
const results = await PostModel.find({
10-
where: {
11-
draft: false
12-
}
13-
})
4+
// Function to get all blog posts
5+
export const getRemoteBlogPosts = async (): Promise<Post['data'][]> => {
6+
try {
7+
const results = await PostModel.find({
8+
where: {
9+
draft: false
10+
}
11+
})
1412

15-
return results.data.map((post) => post.data)
16-
} catch (error) {
17-
console.error('Error fetching remote blog posts:', error)
18-
return []
19-
}
20-
},
21-
['blog-posts'], // cache key
22-
{
23-
revalidate: 3600, // revalidate every hour
24-
tags: ['blog-posts']
13+
return results.data.map((post) => post.data)
14+
} catch (error) {
15+
console.error('Error fetching remote blog posts:', error)
16+
return []
2517
}
26-
)
27-
28-
// Function to get a single blog post by slug with Next.js caching
29-
export const getRemoteBlogPost = unstable_cache(
30-
async (slug: string): Promise<Post['data'] | null> => {
31-
try {
32-
const result = await PostModel.findOne({
33-
where: {
34-
slug
35-
}
36-
})
18+
}
3719

38-
if (result.exists()) {
39-
return result.data
40-
} else {
41-
console.warn(`No blog post found with slug "${slug}"`)
42-
return null
20+
// Function to get a single blog post by slug
21+
export const getRemoteBlogPost = async (slug: string): Promise<Post['data'] | null> => {
22+
try {
23+
const result = await PostModel.findOne({
24+
where: {
25+
slug
4326
}
44-
} catch (error) {
45-
console.error(`Error fetching remote blog post with slug "${slug}":`, error)
27+
})
28+
29+
if (result.exists()) {
30+
return result.data
31+
} else {
32+
console.warn(`No blog post found with slug "${slug}"`)
4633
return null
4734
}
48-
},
49-
['blog-post'], // cache key prefix
50-
{
51-
revalidate: 3600, // revalidate every hour
52-
tags: ['blog-post']
35+
} catch (error) {
36+
console.error(`Error fetching remote blog post with slug "${slug}":`, error)
37+
return null
5338
}
54-
)
39+
}
5540

56-
// Function to get a single page by slug with Next.js caching
57-
export const getRemotePage = unstable_cache(
58-
async (slug: string): Promise<Page['data'] | null> => {
59-
try {
60-
const result = await PageModel.findOne({
61-
where: {
62-
slug,
63-
draft: false
64-
}
65-
})
66-
if (result.exists()) {
67-
return result.data
68-
} else {
69-
console.warn(`No page found with slug "${slug}"`)
70-
return null
41+
// Function to get a single page by slug
42+
export const getRemotePage = async (slug: string): Promise<Page['data'] | null> => {
43+
try {
44+
const result = await PageModel.findOne({
45+
where: {
46+
slug,
47+
draft: false
7148
}
72-
} catch (error) {
73-
console.error(`Error fetching remote page with slug "${slug}":`, error)
49+
})
50+
if (result.exists()) {
51+
return result.data
52+
} else {
53+
console.warn(`No page found with slug "${slug}"`)
7454
return null
7555
}
76-
},
77-
['page'], // cache key prefix
78-
{
79-
revalidate: 3600, // revalidate every hour
80-
tags: ['page']
56+
} catch (error) {
57+
console.error(`Error fetching remote page with slug "${slug}":`, error)
58+
return null
8159
}
82-
)
60+
}
8361

84-
// Function to get featured blog posts with Next.js caching
85-
export const getFeaturedBlogPosts = unstable_cache(
86-
async (limit?: number): Promise<Post['data'][]> => {
87-
try {
88-
const results = await PostModel.find({
89-
where: {
90-
draft: false,
91-
featured: true
92-
},
93-
limit
94-
})
62+
// Function to get featured blog posts
63+
export const getFeaturedBlogPosts = async (limit?: number): Promise<Post['data'][]> => {
64+
try {
65+
const results = await PostModel.find({
66+
where: {
67+
draft: false,
68+
featured: true
69+
},
70+
limit
71+
})
9572

96-
return results.data.map((post) => post.data)
97-
} catch (error) {
98-
console.error('Error fetching featured blog posts:', error)
99-
return []
100-
}
101-
},
102-
['featured-blog-posts'], // cache key
103-
{
104-
revalidate: 3600, // revalidate every hour
105-
tags: ['featured-blog-posts']
73+
return results.data.map((post) => post.data)
74+
} catch (error) {
75+
console.error('Error fetching featured blog posts:', error)
76+
return []
10677
}
107-
)
78+
}

0 commit comments

Comments
 (0)