Skip to content
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
1 change: 1 addition & 0 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2642,6 +2642,7 @@ export default abstract class Server<
// propagate the request context for dev
setRequestMeta(request, getRequestMeta(req))
addRequestMeta(request, 'projectDir', this.dir)
addRequestMeta(request, 'distDir', this.distDir)
addRequestMeta(request, 'isIsrFallback', pagesFallback)
addRequestMeta(request, 'query', query)
addRequestMeta(request, 'params', opts.params)
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ export default class NextNodeServer extends BaseServer<
) => Promise<void>
}
addRequestMeta(req.originalRequest, 'projectDir', this.dir)
addRequestMeta(req.originalRequest, 'distDir', this.distDir)
await module.handler(req.originalRequest, res.originalResponse, {
waitUntil: this.getWaitUntil(),
})
Expand Down
5 changes: 5 additions & 0 deletions packages/next/src/server/request-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ export interface RequestMeta {
*/
projectDir?: string

/**
* The dist directory the server is currently using
*/
distDir?: string

/**
* Whether we are generating the fallback version of the page in dev mode
*/
Expand Down
8 changes: 7 additions & 1 deletion packages/next/src/server/route-modules/route-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,17 @@ export abstract class RouteModule<
// if we want to share the normalizing logic here
// we will need to allow passing in the i18n and similar info
if (process.env.NEXT_RUNTIME !== 'edge') {
const { join } = require('node:path') as typeof import('node:path')
const { join, relative } =
require('node:path') as typeof import('node:path')
const projectDir =
getRequestMeta(req, 'projectDir') ||
join(process.cwd(), this.projectDir)

const absoluteDistDir = getRequestMeta(req, 'distDir')

if (absoluteDistDir) {
this.distDir = relative(projectDir, absoluteDistDir)
}
const { ensureInstrumentationRegistered } = await import(
'../lib/router-utils/instrumentation-globals.external'
)
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/app-dir/nx-handling/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
50 changes: 50 additions & 0 deletions test/e2e/app-dir/nx-handling/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# See https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files for more about ignoring files.

# compiled output
dist
tmp
out-tsc

# dependencies
node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db

.nx/cache
.nx/workspace-data
.cursor/rules/nx-rules.mdc
.github/instructions/nx.instructions.md

# Next.js
.next
out
.nx
.vscode
1 change: 1 addition & 0 deletions test/e2e/app-dir/nx-handling/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps=true
30 changes: 30 additions & 0 deletions test/e2e/app-dir/nx-handling/apps/next-nx-test/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"jsc": {
"target": "es2017",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true
},
"keepClassNames": true,
"externalHelpers": true,
"loose": true
},
"module": {
"type": "commonjs"
},
"sourceMaps": true,
"exclude": [
"jest.config.ts",
".*\\.spec.tsx?$",
".*\\.test.tsx?$",
"./src/jest-setup.ts$",
"./**/jest-setup.ts$",
".*.js$",
".*.d.ts$"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function GET(request: Request) {
return new Response('Hello, from API!')
}
Loading