Skip to content

Commit 3b26573

Browse files
authored
fix: correctly find site root when using SSR with Nx (#1281)
* fix: conditionally change working directory * feat: add ssr route for testing
1 parent 0121255 commit 3b26573

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
3+
export default function handler(req, res) {
4+
res.status(200).json({
5+
body: 'Hello world',
6+
});
7+
}

src/templates/getHandler.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ type Mutable<T> = {
2727
// We return a function and then call `toString()` on it to serialise it as the launcher function
2828
// eslint-disable-next-line max-params
2929
const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[string, string]> = [], mode = 'ssr') => {
30-
// Change working directory into the site root
30+
// Change working directory into the site root, unless using Nx, which moves the
31+
// dist directory and handles this itself
3132
const dir = path.resolve(__dirname, app)
32-
33-
process.chdir(dir)
33+
if (pageRoot.startsWith(dir)) {
34+
process.chdir(dir)
35+
}
3436

3537
// This is just so nft knows about the page entrypoints. It's not actually used
3638
try {

0 commit comments

Comments
 (0)