Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change working directory to site root in SSR #1265

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/default/pages/api/hello.js
Original file line number Diff line number Diff line change
@@ -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() })
}
7 changes: 6 additions & 1 deletion src/templates/getHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ type Mutable<T> = {
// 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
Expand Down Expand Up @@ -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,
Expand Down