Skip to content

Commit 93c85f0

Browse files
authored
Merge branch 'main' into template-updates
2 parents dd19f80 + cce048a commit 93c85f0

File tree

7 files changed

+67
-49
lines changed

7 files changed

+67
-49
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,44 @@ If your site uses pnpm to manage dependencies, currently you must
174174
public-hoist-pattern[]=*
175175
```
176176

177+
## Running the tests
178+
179+
To run the tests, ensure that the dependencies are installed as follows:
180+
181+
```shell
182+
npm install
183+
```
184+
185+
Then run the tests:
186+
187+
```shell
188+
npm test
189+
```
190+
191+
### End-to-end tests
192+
193+
In order to run the end-to-end (E2E) tests, you'll need to be logged in to Netlify. You can do this using the [Netlify CLI](https://github.com/netlify/cli) with the command:
194+
195+
```shell
196+
netlify login
197+
```
198+
199+
Alternatively, you can set an environment variable `NETLIFY_AUTH_TOKEN` to a valid Netlify personal access token. This can be obtained from the [Netlify UI](https://docs.netlify.com/cli/get-started/#obtain-a-token-in-the-netlify-ui).
200+
201+
Then run the E2E tests if logged in:
202+
203+
```shell
204+
npm run test:next
205+
```
206+
207+
Or if using an access token:
208+
209+
```shell
210+
NETLIFY_AUTH_TOKEN=your-token-here npm run test:next
211+
```
212+
213+
_Note: The E2E tests will be deployed to a Netlify owned site. To deploy to your own site then set the environment variable `NETLIFY_SITE_ID` to your site ID._
214+
177215
## Feedback
178216

179217
If you think you have found a bug in Next.js on Netlify,

package-lock.json

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/runtime/src/helpers/functions.ts

Lines changed: 0 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 9 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 8 additions & 18 deletions
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)