MCPcopy
hub / github.com/vercel/next.js / loadNodeMiddleware

Method loadNodeMiddleware

packages/next/src/server/next-server.ts:1547–1580  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1545 }
1546
1547 private async loadNodeMiddleware() {
1548 if (!process.env.NEXT_MINIMAL) {
1549 try {
1550 const functionsConfig = this.dev
1551 ? {}
1552 : require(
1553 join(
1554 /* turbopackIgnore: true */ this.distDir,
1555 'server',
1556 FUNCTIONS_CONFIG_MANIFEST
1557 )
1558 )
1559
1560 if (this.dev || functionsConfig?.functions?.['/_middleware']) {
1561 // if used with top level await, this will be a promise
1562 return require(
1563 join(
1564 /* turbopackIgnore: true */ this.distDir,
1565 'server',
1566 'middleware.js'
1567 )
1568 )
1569 }
1570 } catch (err) {
1571 if (
1572 isError(err) &&
1573 err.code !== 'ENOENT' &&
1574 err.code !== 'MODULE_NOT_FOUND'
1575 ) {
1576 throw err
1577 }
1578 }
1579 }
1580 }
1581
1582 /**
1583 * Checks if a middleware exists. This method is useful for the development

Callers 3

getMiddlewareMethod · 0.95
hasMiddlewareMethod · 0.95
runMiddlewareMethod · 0.95

Calls 3

joinFunction · 0.90
requireFunction · 0.50
isErrorFunction · 0.50

Tested by

no test coverage detected