Skip to content

Commit

Permalink
fix: do not load server config on middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasio committed Apr 2, 2024
1 parent f0e57c0 commit c89dbe5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/src/config/withHeadstartWPConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export function withHeadstartWPConfig(
operations: [
new ConcatOperation(
'start',
options.isServer
options.isServer && options.nextRuntime === 'nodejs'
? importSetHeadlessServerConfig
: importSetHeadlessClientConfig,
),
Expand Down
16 changes: 16 additions & 0 deletions projects/wp-nextjs/headstartwp.config.server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const { getRedisClient } = require('@10up/next-redis-cache-provider');
const baseConfig = require('./headstartwp.config.client');

const redisClient = getRedisClient();

/**
* Config
*
Expand All @@ -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);
},
},
},
};

0 comments on commit c89dbe5

Please sign in to comment.