You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're running a custom server next site on AWS Lightsail (2 GB RAM, 1 vCPU) and to improve performance we implemented cacheable-response based on the updated example version #18786. But we had large issues with the Node server choking on 50 users. I know it's very vague, but I'm wondering if it was something to do with our custom server config in conjunction with cacheable-response with getServerSideProps. I posted here but no resposne, and was just wondering if you might know or an issue or can see an issue.
server.js
constexpress=require('express')constnext=require('next')constcompression=require('compression')constcacheableResponse=require('cacheable-response')constport=process.env.PORT||3000constdev=process.env.NODE_ENV_CUSTOM==='dev'constapp=next({ dev })consthandle=app.getRequestHandler()constCACHE_MAX_AGE=dev
? 1// for dev, to disable caching
: 1000*60*60// for !dev, 1hrapp.prepare().then(()=>{constserver=express()server.enable('strict routing')server.use(compression())// Caching// Disable on _next filesserver.get('/_next/*',(req,res)=>handle(req,res))// Disable on static filesserver.get('/static/*',(req,res)=>handle(req,res))// Disable on API endpoints within NextJSserver.all('/api/*',(req,res)=>handle(req,res))server.all('*',(req,res)=>{// NextJS issue with handling URL /_error// https://github.com/vercel/next.js/issues/9443if(req.originalUrl==='/_error'){res.redirect(301,'/page-not-found')}returnssrCache(req,res)})server.listen(port,err=>{if(err)throwerrconsole.log(`> Ready on port ${port} 💁🏻♀️`)})}).catch(ex=>{console.error(ex.stack)process.exit(1)})constssrCache=cacheableResponse({ttl: CACHE_MAX_AGE,get: async({ req, res })=>{constrawResEnd=res.endconstdata=awaitnewPromise(resolve=>{res.end=payload=>resolve(payload)app.render(req,res,req.path,{
...req.query,
...req.params})})res.end=rawResEndreturn{ data }},send: ({ data, res })=>res.send(data)})
I'm not using Next.js with cacheable-response, so I can't say too much more.
cacheable-response is a generic cache layer library. Although it can be connected with any codebase (or at least that's the intention), probably Next.js internal API is too opinionated and susceptible to change in a short period of time, making the job really hard.
We're running a custom server next site on AWS Lightsail (2 GB RAM, 1 vCPU) and to improve performance we implemented cacheable-response based on the updated example version #18786. But we had large issues with the Node server choking on 50 users. I know it's very vague, but I'm wondering if it was something to do with our custom server config in conjunction with cacheable-response with getServerSideProps. I posted here but no resposne, and was just wondering if you might know or an issue or can see an issue.
server.js
_document.js
_app.js
index.js
The text was updated successfully, but these errors were encountered: