From c89dbe58705ac56e9e621813302bf638bc8fb528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Tue, 2 Apr 2024 07:20:47 -0300 Subject: [PATCH] fix: do not load server config on middleware --- .../next/src/config/withHeadstartWPConfig.ts | 2 +- projects/wp-nextjs/headstartwp.config.server.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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); + }, + }, }, };