Skip to content

Commit 8b72920

Browse files
committed
support async next configs
1 parent 074d6a0 commit 8b72920

File tree

5 files changed

+137
-143
lines changed

5 files changed

+137
-143
lines changed
Lines changed: 105 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
tests:
2-
# - name: with-js-config-object-style
3-
# config: |
4-
# /** @type {import('next').NextConfig} */
5-
# const nextConfig = {
6-
# reactStrictMode: true,
7-
# async headers() {
8-
# return [
9-
# {
10-
# source: '/:path*',
11-
# headers: [
12-
# {
13-
# key: 'x-custom-header',
14-
# value: 'js-config-value',
15-
# },
16-
# {
17-
# key: 'x-config-type',
18-
# value: 'object',
19-
# },
20-
# ],
21-
# },
22-
# ];
23-
# },
24-
# };
2+
- name: with-js-config-object-style
3+
config: |
4+
/** @type {import('next').NextConfig} */
5+
const nextConfig = {
6+
reactStrictMode: true,
7+
async headers() {
8+
return [
9+
{
10+
source: '/:path*',
11+
headers: [
12+
{
13+
key: 'x-custom-header',
14+
value: 'js-config-value',
15+
},
16+
{
17+
key: 'x-config-type',
18+
value: 'object',
19+
},
20+
],
21+
},
22+
];
23+
},
24+
};
2525
26-
# module.exports = nextConfig;
27-
# file: next.config.js
28-
# - name: with-js-config-function-style
29-
# config: |
30-
# /** @type {import('next').NextConfig} */
31-
# const nextConfig = (phase, { defaultConfig }) => {
32-
# return {
33-
# reactStrictMode: true,
34-
# async headers() {
35-
# return [
36-
# {
37-
# source: '/:path*',
38-
# headers: [
39-
# {
40-
# key: 'x-custom-header',
41-
# value: 'js-config-value',
42-
# },
43-
# {
44-
# key: 'x-config-type',
45-
# value: 'function',
46-
# },
47-
# ],
48-
# },
49-
# ];
50-
# }
51-
# };
52-
# };
26+
module.exports = nextConfig;
27+
file: next.config.js
28+
- name: with-js-config-function-style
29+
config: |
30+
/** @type {import('next').NextConfig} */
31+
const nextConfig = (phase, { defaultConfig }) => {
32+
return {
33+
reactStrictMode: true,
34+
async headers() {
35+
return [
36+
{
37+
source: '/:path*',
38+
headers: [
39+
{
40+
key: 'x-custom-header',
41+
value: 'js-config-value',
42+
},
43+
{
44+
key: 'x-config-type',
45+
value: 'function',
46+
},
47+
],
48+
},
49+
];
50+
}
51+
};
52+
};
5353
54-
# module.exports = nextConfig;
55-
# file: next.config.js
54+
module.exports = nextConfig;
55+
file: next.config.js
5656
- name: with-js-async-function
5757
config: |
5858
// @ts-check
@@ -83,62 +83,62 @@ tests:
8383
return nextConfig
8484
}
8585
file: next.config.js
86-
# - name: with-ts-config
87-
# config: |
88-
# import type { NextConfig } from 'next'
86+
- name: with-ts-config
87+
config: |
88+
import type { NextConfig } from 'next'
8989
90-
# const nextConfig: NextConfig = {
91-
# async headers() {
92-
# return [
93-
# {
94-
# source: '/:path*',
95-
# headers: [
96-
# {
97-
# key: 'x-custom-header',
98-
# value: 'ts-config-value',
99-
# }
100-
# ],
101-
# },
102-
# ];
103-
# }
104-
# }
90+
const nextConfig: NextConfig = {
91+
async headers() {
92+
return [
93+
{
94+
source: '/:path*',
95+
headers: [
96+
{
97+
key: 'x-custom-header',
98+
value: 'ts-config-value',
99+
}
100+
],
101+
},
102+
];
103+
}
104+
}
105105
106-
# export default nextConfig
107-
# file: next.config.ts
108-
# - name: with-ecmascript-modules
109-
# config: |
110-
# // @ts-check
106+
export default nextConfig
107+
file: next.config.ts
108+
- name: with-ecmascript-modules
109+
config: |
110+
// @ts-check
111111
112-
# /**
113-
# * @type {import('next').NextConfig}
114-
# */
115-
# const nextConfig = {
116-
# /* config options here */
117-
# async headers() {
118-
# return [
119-
# {
120-
# source: '/:path*',
121-
# headers: [
122-
# {
123-
# key: 'x-custom-header',
124-
# value: 'mjs-config-value',
125-
# },
126-
# ],
127-
# },
128-
# ];
129-
# }
130-
# }
112+
/**
113+
* @type {import('next').NextConfig}
114+
*/
115+
const nextConfig = {
116+
/* config options here */
117+
async headers() {
118+
return [
119+
{
120+
source: '/:path*',
121+
headers: [
122+
{
123+
key: 'x-custom-header',
124+
value: 'mjs-config-value',
125+
},
126+
],
127+
},
128+
];
129+
}
130+
}
131131
132-
# export default nextConfig
133-
# file: next.config.mjs
134-
# - name: with-empty-config
135-
# config: |
136-
# // @ts-check
132+
export default nextConfig
133+
file: next.config.mjs
134+
- name: with-empty-config
135+
config: |
136+
// @ts-check
137137
138-
# /** @type {import('next').NextConfig} */
139-
# const nextConfig = {
140-
# /* config options here */
141-
# }
138+
/** @type {import('next').NextConfig} */
139+
const nextConfig = {
140+
/* config options here */
141+
}
142142
143-
# module.exports = nextConfig
144-
# file: next.config.js
143+
module.exports = nextConfig
144+
file: next.config.js

packages/@apphosting/adapter-nextjs/e2e/config-override.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ describe("next.config override", () => {
5454
// We'll check for the custom header that was set in the next.config
5555
const response = await fetch(posix.join(host, "/"));
5656

57-
// Log all headers individually for debugging
58-
console.log("Response headers:");
59-
response.headers.forEach((value, key) => {
60-
console.log(` ${key}: ${value}`);
61-
});
62-
6357
assert.ok(response.ok);
6458

6559
// Check for the custom header that was set in the next.config

packages/@apphosting/adapter-nextjs/e2e/run-local.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,33 @@ const configOverrideTestScenarios = parseYaml(
2525
).tests;
2626

2727
const scenarios: Scenario[] = [
28-
// {
29-
// name: "basic",
30-
// // No setup needed for basic scenario
31-
// tests: ["app.spec.ts"],
32-
// },
33-
// {
34-
// name: "with-middleware",
35-
// setup: async (cwd: string) => {
36-
// // Create a middleware.ts file
37-
// const middlewareContent = `
38-
// import type { NextRequest } from 'next/server'
39-
40-
// export function middleware(request: NextRequest) {
41-
// // This is a simple middleware that doesn't modify the request
42-
// console.log('Middleware executed', request.nextUrl.pathname);
43-
// }
44-
45-
// export const config = {
46-
// matcher: '/((?!api|_next/static|_next/image|favicon.ico).*)',
47-
// };
48-
// `;
49-
50-
// await fsExtra.writeFile(join(cwd, "src", "middleware.ts"), middlewareContent);
51-
// console.log(`Created middleware.ts file`);
52-
// },
53-
// tests: ["middleware.spec.ts"], // Only run middleware-specific tests
54-
// },
28+
{
29+
name: "basic",
30+
// No setup needed for basic scenario
31+
tests: ["app.spec.ts"],
32+
},
33+
{
34+
name: "with-middleware",
35+
setup: async (cwd: string) => {
36+
// Create a middleware.ts file
37+
const middlewareContent = `
38+
import type { NextRequest } from 'next/server'
39+
40+
export function middleware(request: NextRequest) {
41+
// This is a simple middleware that doesn't modify the request
42+
console.log('Middleware executed', request.nextUrl.pathname);
43+
}
44+
45+
export const config = {
46+
matcher: '/((?!api|_next/static|_next/image|favicon.ico).*)',
47+
};
48+
`;
49+
50+
await fsExtra.writeFile(join(cwd, "src", "middleware.ts"), middlewareContent);
51+
console.log(`Created middleware.ts file`);
52+
},
53+
tests: ["middleware.spec.ts"], // Only run middleware-specific tests
54+
},
5555
...configOverrideTestScenarios.map(
5656
(scenario: { name: string; config: string; file: string }) => ({
5757
name: scenario.name,

packages/@apphosting/adapter-nextjs/src/overrides.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ describe("next config overrides", () => {
179179
});
180180
181181
const config = typeof originalConfig === 'function'
182-
? (...args) => {
183-
const resolvedConfig = originalConfig(...args);
182+
? async (...args) => {
183+
const resolvedConfig = await originalConfig(...args);
184184
return fahOptimizedConfig(resolvedConfig);
185185
}
186186
: fahOptimizedConfig(originalConfig);
187-
`;
187+
`;
188188

189189
beforeEach(() => {
190190
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "test-overrides"));

packages/@apphosting/adapter-nextjs/src/overrides.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ function getCustomNextConfig(importStatement: string, fileExtension: string) {
6969
});
7070
7171
const config = typeof originalConfig === 'function'
72-
? (...args) => {
73-
const resolvedConfig = originalConfig(...args);
72+
? async (...args) => {
73+
const resolvedConfig = await originalConfig(...args);
7474
return fahOptimizedConfig(resolvedConfig);
7575
}
7676
: fahOptimizedConfig(originalConfig);

0 commit comments

Comments
 (0)