diff --git a/packages/next/src/config/withHeadstartWPConfig.ts b/packages/next/src/config/withHeadstartWPConfig.ts index 9e78499cf..098a15e42 100644 --- a/packages/next/src/config/withHeadstartWPConfig.ts +++ b/packages/next/src/config/withHeadstartWPConfig.ts @@ -236,7 +236,7 @@ export function withHeadstartWPConfig( operations: [ new ConcatOperation( 'start', - options.isServer + options.isServer && options.nextRuntime === 'nodejs' ? importSetHeadlessServerConfig : importSetHeadlessClientConfig, ), diff --git a/projects/wp-nextjs/headstartwp.config.server.js b/projects/wp-nextjs/headstartwp.config.server.js index 34b884532..47f4fa190 100644 --- a/projects/wp-nextjs/headstartwp.config.server.js +++ b/projects/wp-nextjs/headstartwp.config.server.js @@ -1,5 +1,8 @@ +const { getRedisClient } = require('@10up/next-redis-cache-provider'); const baseConfig = require('./headstartwp.config.client'); +const redisClient = getRedisClient(); + /** * Config * @@ -12,5 +15,18 @@ module.exports = { // cache app endpoints in-memory by default return fetchStrategy.getEndpoint() === '/wp-json/headless-wp/v1/app'; }, + + /** + * @type {import('@headstartwp/core').FetchStrategyCacheHandler} + */ + cacheHandler: { + async set(key, data, ttl) { + return redisClient.set(key, JSON.stringify(data), 'EX', ttl); + }, + async get(key) { + const data = await redisClient.get(key); + return JSON.parse(data); + }, + }, }, };