-
Hey there, But I can't make cache work on production environment. I'm using Node.js. What I've done:
I explored a code a bit and it seems like when using "createServer" function, it's not possible to override params passed to Can you please provide me with a working code snippet? Or point on what I'm doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In order to apply a cache, you'll want to follow the instructions for "Use a different Node framework" instead: https://shopify.dev/custom-storefronts/hydrogen/deployment#use-a-different-node-js-framework Here's what I have in my project: import {hydrogenMiddleware} from '@shopify/hydrogen/middleware';
import serveStatic from 'serve-static';
import compression from 'compression';
import bodyParser from 'body-parser';
import connect from 'connect';
import path from 'path';
const {
InMemoryCache,
} = require('@shopify/hydrogen/dist/node/framework/cache/in-memory');
const inMemoryCache = new InMemoryCache();
const port = process.env.PORT || 8080;
function createServer() {
const app = connect();
app.use(compression());
app.use(
serveStatic(path.resolve(__dirname, '../', 'client'), {index: false}),
);
app.use(bodyParser.raw({type: '*/*'}));
app.use(
hydrogenMiddleware({
getServerEntrypoint: () => import('./src/App.server'),
indexTemplate: () => import('./dist/client/index.html?raw'),
cache: inMemoryCache,
}),
);
return app;
}
const app = createServer();
app.listen(port, () => {
console.log(`Hydrogen server running at http://localhost:${port}`);
}); FYI, I think this differs slightly from the example in the docs — I will be sure to update the docs. Cache is working in production: https://hydrogen-fly-redis.fly.dev/ (the name implies redis, but it's actually in mem).
|
Beta Was this translation helpful? Give feedback.
In order to apply a cache, you'll want to follow the instructions for "Use a different Node framework" instead: https://shopify.dev/custom-storefronts/hydrogen/deployment#use-a-different-node-js-framework
Here's what I have in my project: