Skip to content

Commit cce048a

Browse files
authored
fix: follow-up to split-api revalidate behaviour (#2113)
* fix: don't flag revalidate behaviour * fix: return handler, don't await
1 parent 4e70c63 commit cce048a

File tree

5 files changed

+11
-31
lines changed

5 files changed

+11
-31
lines changed

packages/runtime/src/helpers/functions.ts

-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const generateFunctions = async (
4848
{ FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR }: NetlifyPluginConstants,
4949
appDir: string,
5050
apiLambdas: APILambda[],
51-
featureFlags: Record<string, unknown>,
5251
): Promise<void> => {
5352
const publish = resolve(PUBLISH_DIR)
5453
const functionsDir = resolve(INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC)
@@ -70,7 +69,6 @@ export const generateFunctions = async (
7069
publishDir,
7170
appDir: relative(functionDir, appDir),
7271
nextServerModuleRelativeLocation,
73-
featureFlags,
7472
})
7573

7674
await ensureDir(join(functionsDir, functionName))

packages/runtime/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ const plugin: NetlifyPlugin = {
172172
extendedRoutes.map(packSingleFunction),
173173
)
174174

175-
await generateFunctions(constants, appDir, apiLambdas, featureFlags)
175+
await generateFunctions(constants, appDir, apiLambdas)
176176
await generatePagesResolver(constants)
177177

178178
await configureHandlerFunctions({

packages/runtime/src/templates/getApiHandler.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { Bridge as NodeBridge } from '@vercel/node-bridge/bridge'
44
import { outdent as javascript } from 'outdent'
55

66
import type { NextConfig } from '../helpers/config'
7-
import { splitApiRoutes as isSplitApiRoutesEnabled } from '../helpers/flags'
87

98
import type { NextServerType } from './handlerUtils'
109
import type { NetlifyNextServerType } from './server'
@@ -31,11 +30,10 @@ type MakeApiHandlerParams = {
3130
app: string
3231
pageRoot: string
3332
NextServer: NextServerType
34-
splitApiRoutes: boolean
3533
}
3634

3735
// We return a function and then call `toString()` on it to serialise it as the launcher function
38-
const makeApiHandler = ({ conf, app, pageRoot, NextServer, splitApiRoutes }: MakeApiHandlerParams) => {
36+
const makeApiHandler = ({ conf, app, pageRoot, NextServer }: MakeApiHandlerParams) => {
3937
// Change working directory into the site root, unless using Nx, which moves the
4038
// dist directory and handles this itself
4139
const dir = path.resolve(__dirname, app)
@@ -90,7 +88,6 @@ const makeApiHandler = ({ conf, app, pageRoot, NextServer, splitApiRoutes }: Mak
9088
},
9189
{
9290
revalidateToken: customContext?.odb_refresh_hooks,
93-
splitApiRoutes,
9491
},
9592
)
9693
const requestHandler = nextServer.getRequestHandler()
@@ -137,13 +134,11 @@ export const getApiHandler = ({
137134
publishDir = '../../../.next',
138135
appDir = '../../..',
139136
nextServerModuleRelativeLocation,
140-
featureFlags,
141137
}: {
142138
schedule?: string
143139
publishDir?: string
144140
appDir?: string
145141
nextServerModuleRelativeLocation: string | undefined
146-
featureFlags: Record<string, unknown>
147142
}): string =>
148143
// This is a string, but if you have the right editor plugin it should format as js (e.g. bierner.comment-tagged-templates in VS Code)
149144
javascript/* javascript */ `
@@ -166,8 +161,6 @@ export const getApiHandler = ({
166161
let staticManifest
167162
const path = require("path");
168163
const pageRoot = path.resolve(path.join(__dirname, "${publishDir}", "server"));
169-
const handler = (${makeApiHandler.toString()})({ conf: config, app: "${appDir}", pageRoot, NextServer, splitApiRoutes: ${isSplitApiRoutesEnabled(
170-
featureFlags,
171-
)} })
164+
const handler = (${makeApiHandler.toString()})({ conf: config, app: "${appDir}", pageRoot, NextServer })
172165
exports.handler = ${schedule ? `schedule(${JSON.stringify(schedule)}, handler);` : 'handler'}
173166
`

packages/runtime/src/templates/getHandler.ts

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ const makeHandler = ({ conf, app, pageRoot, NextServer, staticManifest = [], mod
101101
},
102102
{
103103
revalidateToken: customContext?.odb_refresh_hooks,
104-
splitApiRoutes: false,
105104
},
106105
)
107106
const requestHandler = nextServer.getRequestHandler()

packages/runtime/src/templates/server.ts

+8-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313

1414
interface NetlifyConfig {
1515
revalidateToken?: string
16-
splitApiRoutes: boolean
1716
}
1817

1918
const getNetlifyNextServer = (NextServer: NextServerType) => {
@@ -39,25 +38,16 @@ const getNetlifyNextServer = (NextServer: NextServerType) => {
3938
// preserve the URL before Next.js mutates it for i18n
4039
const { url, headers } = req
4140

42-
if (this.netlifyConfig.splitApiRoutes) {
43-
if (headers['x-prerender-revalidate'] && this.netlifyConfig.revalidateToken) {
44-
// handle on-demand revalidation by purging the ODB cache
45-
await this.netlifyRevalidate(url)
41+
if (headers['x-prerender-revalidate'] && this.netlifyConfig.revalidateToken) {
42+
// handle on-demand revalidation by purging the ODB cache
43+
await this.netlifyRevalidate(url)
4644

47-
res = res as unknown as BaseNextResponse
48-
res.statusCode = 200
49-
res.setHeader('x-nextjs-cache', 'REVALIDATED')
50-
res.send()
51-
} else {
52-
await handler(req, res, parsedUrl)
53-
}
45+
res = res as unknown as BaseNextResponse
46+
res.statusCode = 200
47+
res.setHeader('x-nextjs-cache', 'REVALIDATED')
48+
res.send()
5449
} else {
55-
// handle the original res.revalidate() request
56-
await handler(req, res, parsedUrl)
57-
// handle on-demand revalidation by purging the ODB cache
58-
if (res.statusCode === 200 && headers['x-prerender-revalidate'] && this.netlifyConfig.revalidateToken) {
59-
await this.netlifyRevalidate(url)
60-
}
50+
return handler(req, res, parsedUrl)
6151
}
6252
}
6353
}

0 commit comments

Comments
 (0)