forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "support
runtime: edge
in api endpoints"" (vercel#37344
) Reverts vercel#37337
- Loading branch information
Showing
12 changed files
with
271 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/next/build/webpack/loaders/next-edge-function-loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { getModuleBuildInfo } from './get-module-build-info' | ||
import { stringifyRequest } from '../stringify-request' | ||
|
||
export type EdgeFunctionLoaderOptions = { | ||
absolutePagePath: string | ||
page: string | ||
} | ||
|
||
export default function middlewareLoader(this: any) { | ||
const { absolutePagePath, page }: EdgeFunctionLoaderOptions = | ||
this.getOptions() | ||
const stringifiedPagePath = stringifyRequest(this, absolutePagePath) | ||
const buildInfo = getModuleBuildInfo(this._module) | ||
buildInfo.nextEdgeApiFunction = { | ||
page: page || '/', | ||
} | ||
|
||
return ` | ||
import { adapter } from 'next/dist/server/web/adapter' | ||
// The condition is true when the "process" module is provided | ||
if (process !== global.process) { | ||
// prefer local process but global.process has correct "env" | ||
process.env = global.process.env; | ||
global.process = process; | ||
} | ||
var mod = require(${stringifiedPagePath}) | ||
var handler = mod.middleware || mod.default; | ||
if (typeof handler !== 'function') { | ||
throw new Error('The Edge Function "pages${page}" must export a \`default\` function'); | ||
} | ||
export default function (opts) { | ||
return adapter({ | ||
...opts, | ||
page: ${JSON.stringify(page)}, | ||
handler, | ||
}) | ||
} | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test/integration/react-streaming-and-server-components/switchable-runtime/pages/api/hello.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default (req) => { | ||
return new Response(`Hello from ${req.url}`) | ||
} | ||
|
||
export const config = { | ||
runtime: 'edge', | ||
} |
Oops, something went wrong.