Skip to content

Commit 91ea2a6

Browse files
committed
chore: renamed getApiRoutes to make it clearer what it is getting
1 parent c0b22dd commit 91ea2a6

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

packages/runtime/src/helpers/functions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ export const setupImageFunction = async ({
165165
}
166166

167167
/**
168-
* Look for API routes, and extract the config from the source file.
168+
* Look for advanced API routes (background and scheduled functions), and extract the config from the source file.
169169
*/
170-
export const getApiRouteConfigs = async (publish: string, baseDir: string): Promise<Array<ApiRouteConfig>> => {
170+
export const getAdvancedApiRouteConfigs = async (publish: string, baseDir: string): Promise<Array<ApiRouteConfig>> => {
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')
@@ -179,6 +179,7 @@ export const getApiRouteConfigs = async (publish: string, baseDir: string): Prom
179179
}),
180180
)
181181

182+
// We only want to return the API routes that are background or scheduled functions
182183
return settledApiRoutes.filter((apiRoute) => apiRoute.config.type !== undefined)
183184
}
184185

packages/runtime/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
generateFunctions,
2424
setupImageFunction,
2525
generatePagesResolver,
26-
getApiRouteConfigs,
26+
getAdvancedApiRouteConfigs,
2727
warnOnApiRoutes,
2828
} from './helpers/functions'
2929
import { generateRedirects, generateStaticRedirects } from './helpers/redirects'
@@ -152,7 +152,7 @@ const plugin: NetlifyPlugin = {
152152
const buildId = readFileSync(join(publish, 'BUILD_ID'), 'utf8').trim()
153153

154154
await configureHandlerFunctions({ netlifyConfig, ignore, publish: relative(process.cwd(), publish) })
155-
const apiRoutes = await getApiRouteConfigs(publish, appDir)
155+
const apiRoutes = await getAdvancedApiRouteConfigs(publish, appDir)
156156

157157
await generateFunctions(constants, appDir, apiRoutes)
158158
await generatePagesResolver({ target, constants })

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const os = require('os')
1313
const cpy = require('cpy')
1414
const { dir: getTmpDir } = require('tmp-promise')
1515
const { downloadFile } = require('../packages/runtime/src/templates/handlerUtils')
16-
const { getApiRouteConfigs } = require('../packages/runtime/src/helpers/functions')
16+
const { getAdvancedApiRouteConfigs } = require('../packages/runtime/src/helpers/functions')
1717
const nextRuntimeFactory = require('../packages/runtime/src')
1818
const nextRuntime = nextRuntimeFactory({})
1919

@@ -1623,7 +1623,7 @@ describe('function helpers', () => {
16231623
describe('api route file analysis', () => {
16241624
it('extracts correct route configs from source files', async () => {
16251625
await moveNextDist()
1626-
const configs = await getApiRouteConfigs('.next', process.cwd())
1626+
const configs = await getAdvancedApiRouteConfigs('.next', process.cwd())
16271627
// Using a Set means the order doesn't matter
16281628
expect(new Set(configs)).toEqual(
16291629
new Set([

0 commit comments

Comments
 (0)