Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ssr-caching example #12180

Merged
merged 7 commits into from
May 22, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions examples/ssr-caching/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const handle = app.getRequestHandler()

const ssrCache = cacheableResponse({
ttl: 1000 * 60 * 60, // 1hour
get: async ({ req, res, pagePath, queryParams }) => {
const data = await app.renderToHTML(req, res, pagePath, queryParams)
get: async ({ req, res }) => {
const data = await app.renderToHTML(req, res, req.path, {...req.query, ...req.params})

// Add here custom logic for when you do not want to cache the page, for
// example when the page returns a 404 status code:
Expand All @@ -28,12 +28,10 @@ const ssrCache = cacheableResponse({
app.prepare().then(() => {
const server = express()

server.get('/', (req, res) => ssrCache({ req, res, pagePath: '/' }))
server.get('/', (req, res) => ssrCache({ req, res }))

server.get('/blog/:id', (req, res) => {
const queryParams = { id: req.params.id }
const pagePath = '/blog'
return ssrCache({ req, res, pagePath, queryParams })
return ssrCache({ req, res })
})

server.get('*', (req, res) => handle(req, res))
Expand Down