diff --git a/demos/nx-next-monorepo-demo/apps/demo-monorepo/pages/api/index.js b/demos/nx-next-monorepo-demo/apps/demo-monorepo/pages/api/index.js new file mode 100644 index 0000000000..78c308caf2 --- /dev/null +++ b/demos/nx-next-monorepo-demo/apps/demo-monorepo/pages/api/index.js @@ -0,0 +1,7 @@ +// Next.js API route support: https://nextjs.org/docs/api-routes/introduction + +export default function handler(req, res) { + res.status(200).json({ + body: 'Hello world', + }); +} diff --git a/src/templates/getHandler.ts b/src/templates/getHandler.ts index 2e4121a235..e19e11080b 100644 --- a/src/templates/getHandler.ts +++ b/src/templates/getHandler.ts @@ -27,10 +27,12 @@ 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 + // Change working directory into the site root, unless using Nx, which moves the + // dist directory and handles this itself const dir = path.resolve(__dirname, app) - - process.chdir(dir) + if (pageRoot.startsWith(dir)) { + process.chdir(dir) + } // This is just so nft knows about the page entrypoints. It's not actually used try {