diff --git a/demos/default/pages/api/hello.js b/demos/default/pages/api/hello.js index 18d3d7b206..d8d6130fcb 100644 --- a/demos/default/pages/api/hello.js +++ b/demos/default/pages/api/hello.js @@ -1,5 +1,5 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction export default (req, res) => { - res.status(200).json({ name: 'John Doe', query: req.query, env: process.env.HELLO_WORLD }) + res.status(200).json({ name: 'John Doe', query: req.query, env: process.env.HELLO_WORLD, cwd: process.cwd() }) } diff --git a/src/templates/getHandler.ts b/src/templates/getHandler.ts index be2d922858..574460804d 100644 --- a/src/templates/getHandler.ts +++ b/src/templates/getHandler.ts @@ -27,6 +27,11 @@ type Mutable = { // We return a function and then call `toString()` on it to serialise it as the launcher function // eslint-disable-next-line max-params const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[string, string]> = [], mode = 'ssr') => { + // Change working directory into the site root + const dir = path.resolve(__dirname, app) + + process.chdir(dir) + // This is just so nft knows about the page entrypoints. It's not actually used try { // eslint-disable-next-line node/no-missing-require @@ -65,7 +70,7 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str const NextServer: NextServerType = getNextServer() const nextServer = new NextServer({ conf, - dir: path.resolve(__dirname, app), + dir, customServer: false, hostname: url.hostname, port,