Skip to content

Commit

Permalink
chore: use opt-out for edge at build/dev time
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Aug 18, 2022
1 parent 398efb1 commit 2f28454
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
5 changes: 1 addition & 4 deletions demos/middleware/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ command = "npm run build"
publish = ".next"
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../..; fi;"

[build.environment]
NEXT_USE_NETLIFY_EDGE = "true"

[[plugins]]
package = "../plugin-wrapper/"
package = "@netlify/plugin-nextjs"

# This is a fake plugin, that makes it run npm install
[[plugins]]
Expand Down
2 changes: 0 additions & 2 deletions packages/runtime/src/helpers/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ export const writeEdgeFunctions = async (netlifyConfig: NetlifyConfig) => {
export const enableEdgeInNextConfig = async (publish: string) => {
const configFile = join(publish, 'required-server-files.json')
const config = await readJSON(configFile)
// This is for runtime in Next.js, rather than a build plugin setting
config.config.env.NEXT_USE_NETLIFY_EDGE = 'true'
await writeJSON(configFile, config)
}
/* eslint-enable max-lines */
8 changes: 4 additions & 4 deletions packages/runtime/src/helpers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,19 @@ const baseServerReplacements: Array<[string, string]> = [
const nextServerReplacements: Array<[string, string]> = [
[
`getMiddlewareManifest() {\n if (this.minimalMode) return null;`,
`getMiddlewareManifest() {\n if (this.minimalMode || process.env.NEXT_USE_NETLIFY_EDGE) return null;`,
`getMiddlewareManifest() {\n if (this.minimalMode || !process.env.NEXT_DISABLE_NETLIFY_EDGE) return null;`,
],
[
`generateCatchAllMiddlewareRoute(devReady) {\n if (this.minimalMode) return []`,
`generateCatchAllMiddlewareRoute(devReady) {\n if (this.minimalMode || process.env.NEXT_USE_NETLIFY_EDGE) return [];`,
`generateCatchAllMiddlewareRoute(devReady) {\n if (this.minimalMode || !process.env.NEXT_DISABLE_NETLIFY_EDGE) return [];`,
],
[
`generateCatchAllMiddlewareRoute() {\n if (this.minimalMode) return undefined;`,
`generateCatchAllMiddlewareRoute() {\n if (this.minimalMode || process.env.NEXT_USE_NETLIFY_EDGE) return undefined;`,
`generateCatchAllMiddlewareRoute() {\n if (this.minimalMode || !process.env.NEXT_DISABLE_NETLIFY_EDGE) return undefined;`,
],
[
`getMiddlewareManifest() {\n if (this.minimalMode) {`,
`getMiddlewareManifest() {\n if (!this.minimalMode && !process.env.NEXT_USE_NETLIFY_EDGE) {`,
`getMiddlewareManifest() {\n if (!this.minimalMode && process.env.NEXT_DISABLE_NETLIFY_EDGE) {`,
],
]

Expand Down

0 comments on commit 2f28454

Please sign in to comment.