Skip to content

Commit

Permalink
fix: include routes in functions config on deploy (#6027)
Browse files Browse the repository at this point in the history
* fix: include `routes` in functions config on deploy

* chore: write test

* chore: remove test.only

* fix: fetch is not defined
  • Loading branch information
Skn0tt authored Sep 28, 2023
1 parent 8360547 commit f83327e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/utils/deploy/hash-fns.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ const hashFns = async (
}),
)
const fnConfig = functionZips
.filter((func) => Boolean(func.displayName || func.generator))
.filter((func) => Boolean(func.displayName || func.generator || func.routes))
.reduce(
(funcs, curr) => ({ ...funcs, [curr.name]: { display_name: curr.displayName, generator: curr.generator } }),
(funcs, curr) => ({
...funcs,
[curr.name]: { display_name: curr.displayName, generator: curr.generator, routes: curr.routes },
}),
{},
)
const functionSchedules = functionZips
Expand Down
12 changes: 9 additions & 3 deletions tests/integration/210.command.deploy.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { join } = require('path')
const process = require('process')

const test = require('ava')
const { Response } = require('node-fetch')
const { Response, default: fetch } = require('node-fetch')

const callCli = require('./utils/call-cli.cjs')
const { createLiveTestSite, generateSiteName } = require('./utils/create-live-test-site.cjs')
Expand Down Expand Up @@ -476,7 +476,10 @@ if (process.env.NETLIFY_TEST_DISABLE_LIVE !== 'true') {
}),
})
.withContentFile({
content: `export default async () => new Response("Internal V2 API")`,
content: `
export default async () => new Response("Internal V2 API")
export const config = { path: "/internal-v2-func" }
`,
path: '.netlify/functions-internal/func-4.mjs',
})
.buildAsync()
Expand All @@ -493,7 +496,10 @@ if (process.env.NETLIFY_TEST_DISABLE_LIVE !== 'true') {
t.is(await got(`${deployUrl}/.netlify/functions/func-1`).text(), 'User 1')
t.is(await got(`${deployUrl}/.netlify/functions/func-2`).text(), 'User 2')
t.is(await got(`${deployUrl}/.netlify/functions/func-3`).text(), 'Internal 3')
t.is(await got(`${deployUrl}/.netlify/functions/func-4`).text(), 'Internal V2 API')

const func4Resp = await fetch(`${deployUrl}/.netlify/functions/func-4`)
t.is(func4Resp.status, 404)
t.is(await got(`${deployUrl}/internal-v2-func`).text(), 'Internal V2 API')
})
})

Expand Down

2 comments on commit f83327e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,367
  • Package size: 376 MB

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,367
  • Package size: 376 MB

Please sign in to comment.