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 38daf34
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 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
9 changes: 5 additions & 4 deletions packages/runtime/src/templates/edge/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ const exists = async (relativePath: string) => {
}

const handler = async (req: Request, context: Context) => {
if (!Deno.env.get('NETLIFY_DEV')) {
// Only run in dev
return
}
// Uncomment when CLI update lands
// if (!Deno.env.get('NETLIFY_DEV')) {
// // Only run in dev
// return
// }

let middleware
// Dynamic imports and FS operations aren't allowed when deployed,
Expand Down

0 comments on commit 38daf34

Please sign in to comment.