Skip to content

Commit 948363c

Browse files
committed
fix: now only custom rewrites are created for background and scheduled functions
1 parent bcd7c11 commit 948363c

File tree

3 files changed

+5
-44
lines changed

3 files changed

+5
-44
lines changed

packages/runtime/src/helpers/functions.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,15 @@ export const getApiRouteConfigs = async (publish: string, baseDir: string): Prom
171171
const pages = await readJSON(join(publish, 'server', 'pages-manifest.json'))
172172
const apiRoutes = Object.keys(pages).filter((page) => page.startsWith('/api/'))
173173
const pagesDir = join(baseDir, 'pages')
174-
return Promise.all(
174+
175+
const settledApiRoutes = await Promise.all(
175176
apiRoutes.map(async (apiRoute) => {
176177
const filePath = getSourceFileForPage(apiRoute, pagesDir)
177178
return { route: apiRoute, config: await extractConfigFromFile(filePath), compiled: pages[apiRoute] }
178179
}),
179180
)
181+
182+
return settledApiRoutes.filter((apiRoute) => apiRoute.config.type !== undefined)
180183
}
181184

182185
interface FunctionsManifest {
@@ -210,7 +213,7 @@ export const warnOnApiRoutes = async ({
210213
if (functions.some((func) => func.schedule)) {
211214
console.warn(
212215
outdent`
213-
${chalk.yellowBright`Using scheduled API routes`}
216+
${chalk.yellowBright`Using scheduled API routes`}
214217
These are run on a schedule when deployed to production.
215218
You can test them locally by loading them in your browser but this will not be available when deployed, and any returned value is ignored.
216219
`,

test/__snapshots__/index.js.snap

-30
Original file line numberDiff line numberDiff line change
@@ -1095,21 +1095,6 @@ Array [
10951095
"status": 200,
10961096
"to": "/.netlify/functions/___netlify-handler",
10971097
},
1098-
Object {
1099-
"from": "/api/enterPreview",
1100-
"status": 200,
1101-
"to": "/.netlify/functions/_api_enterPreview-handler",
1102-
},
1103-
Object {
1104-
"from": "/api/exitPreview",
1105-
"status": 200,
1106-
"to": "/.netlify/functions/_api_exitPreview-handler",
1107-
},
1108-
Object {
1109-
"from": "/api/hello",
1110-
"status": 200,
1111-
"to": "/.netlify/functions/_api_hello-handler",
1112-
},
11131098
Object {
11141099
"from": "/api/hello-background",
11151100
"status": 200,
@@ -1120,21 +1105,6 @@ Array [
11201105
"status": 404,
11211106
"to": "/404.html",
11221107
},
1123-
Object {
1124-
"from": "/api/og",
1125-
"status": 200,
1126-
"to": "/.netlify/functions/_api_og-handler",
1127-
},
1128-
Object {
1129-
"from": "/api/shows/:id",
1130-
"status": 200,
1131-
"to": "/.netlify/functions/_api_shows_id-PARAM-handler",
1132-
},
1133-
Object {
1134-
"from": "/api/shows/:params/*",
1135-
"status": 200,
1136-
"to": "/.netlify/functions/_api_shows_params-SPLAT-handler",
1137-
},
11381108
Object {
11391109
"force": false,
11401110
"from": "/broken-image",

test/index.js

-12
Original file line numberDiff line numberDiff line change
@@ -1627,28 +1627,16 @@ describe('api route file analysis', () => {
16271627
// Using a Set means the order doesn't matter
16281628
expect(new Set(configs)).toEqual(
16291629
new Set([
1630-
{ compiled: 'pages/api/enterPreview.js', config: {}, route: '/api/enterPreview' },
16311630
{
16321631
compiled: 'pages/api/hello-background.js',
16331632
config: { type: 'experimental-background' },
16341633
route: '/api/hello-background',
16351634
},
1636-
{ compiled: 'pages/api/exitPreview.js', config: {}, route: '/api/exitPreview' },
1637-
{ compiled: 'pages/api/shows/[...params].js', config: {}, route: '/api/shows/[...params]' },
1638-
{ compiled: 'pages/api/shows/[id].js', config: {}, route: '/api/shows/[id]' },
1639-
{ compiled: 'pages/api/hello.js', config: {}, route: '/api/hello' },
16401635
{
16411636
compiled: 'pages/api/hello-scheduled.js',
16421637
config: { schedule: '@hourly', type: 'experimental-scheduled' },
16431638
route: '/api/hello-scheduled',
16441639
},
1645-
{
1646-
compiled: 'pages/api/og.js',
1647-
config: {
1648-
runtime: 'experimental-edge',
1649-
},
1650-
route: '/api/og',
1651-
},
16521640
]),
16531641
)
16541642
})

0 commit comments

Comments
 (0)