Skip to content

NextJS 7+ needs app.prepare() #1

@Maxwell2022

Description

@Maxwell2022

I had to add app.prepare() using nextJS 7+

Hopefully it will help anyone facing the same issue:

// server.js
...
const app = next({ dev });

function createServer() {
  const server = express();
  ...
  server.get('*', (req, res) => handle(req, res));
  return server;
}

if (isInLambda) {
  module.exports = { app, createServer };
}
...
// lambda.js
const serverless = require('serverless-http');
const { app, createServer } = require('./server');

const binaryMimeTypes = ['*/*'];

exports.handler = (event, context, callback) => {
  app.prepare().then(() => {
    const server = createServer();
    const handler = serverless(server, {
      binary: binaryMimeTypes,
    });

    return handler(event, context, callback);
  });
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions