@netlify/plugin-nextjs 4.37.0 → 4.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,10 +40,11 @@ const makeApiHandler = ({ conf, app, pageRoot, NextServer }) => {
40
40
  // the first request because we need the host and port.
41
41
  let bridge;
42
42
  const getBridge = (event, context) => {
43
+ var _a;
43
44
  if (bridge) {
44
45
  return bridge;
45
46
  }
46
- const { clientContext: { custom: customContext }, } = context;
47
+ const customContext = (_a = context.clientContext) === null || _a === void 0 ? void 0 : _a.custom;
47
48
  // Scheduled functions don't have a URL, but we need to give one so Next knows the route to serve
48
49
  const url = event.rawUrl ? new URL(event.rawUrl) : new URL(path, process.env.URL || 'http://n');
49
50
  const port = Number.parseInt(url.port) || 80;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.37.0",
3
+ "version": "4.37.1",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@delucis/if-env": "^1.1.2",
40
- "@netlify/build": "^29.11.4",
40
+ "@netlify/build": "^29.11.5",
41
41
  "@types/fs-extra": "^9.0.13",
42
42
  "@types/jest": "^27.4.1",
43
43
  "@types/merge-stream": "^1.1.2",
@@ -1,7 +1,7 @@
1
1
  import { NextRequest } from 'https://esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js'
2
2
  import { NextResponse } from 'https://esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js'
3
3
  import { fromFileUrl } from 'https://deno.land/std@0.151.0/path/mod.ts'
4
- import { buildResponse } from '../edge-shared/utils.ts'
4
+ import { buildResponse, isFunction } from '../edge-shared/utils.ts'
5
5
 
6
6
  globalThis.NFRequestContextMap ||= new Map()
7
7
  globalThis.__dirname = fromFileUrl(new URL('./', import.meta.url)).slice(0, -1)
@@ -36,7 +36,17 @@ const handler = async (req, context) => {
36
36
  // We need to cache-bust the import because otherwise it will claim it
37
37
  // doesn't exist if the user creates it after the server starts
38
38
  const nextMiddleware = await import(`../../middleware.js#${++idx}`)
39
- middleware = nextMiddleware.middleware
39
+
40
+ // The middleware file can export a named `middleware` export or a `default` export
41
+ middleware = isFunction(nextMiddleware.middleware)
42
+ ? nextMiddleware.middleware
43
+ : isFunction(nextMiddleware.default)
44
+ ? nextMiddleware.default
45
+ : undefined
46
+
47
+ if (!middleware) {
48
+ throw new Error('The middleware must export a `middleware` or a `default` function')
49
+ }
40
50
  } catch (importError) {
41
51
  if (importError.code === 'ERR_MODULE_NOT_FOUND' && importError.message.includes(`middleware.js`)) {
42
52
  // No middleware, so we silently return
@@ -305,3 +305,5 @@ export const redirectTrailingSlash = (url: URL, trailingSlash: boolean): Respons
305
305
  return Response.redirect(url, 308)
306
306
  }
307
307
  }
308
+
309
+ export const isFunction = (f: unknown) => Boolean(f) && typeof f === 'function'