Skip to content

Commit c68efb2

Browse files
authored
fix(command-dev): pass full lambda-local result functions server (#2901)
1 parent bbb78bd commit c68efb2

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/lib/functions/runtimes/js/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ const invokeFunction = async ({ context, event, func, timeout }) => {
5454
// If a function builder has defined a `buildPath` property, we use it.
5555
// Otherwise, we'll invoke the function's main file.
5656
const lambdaPath = (func.buildData && func.buildData.buildPath) || func.mainFile
57-
const { body, statusCode } = await lambdaLocal.execute({
57+
const result = await lambdaLocal.execute({
5858
clientContext: context,
5959
event,
6060
lambdaPath,
6161
timeoutMs: timeout * SECONDS_TO_MILLISECONDS,
6262
verboseLevel: 3,
6363
})
6464

65-
return { body, statusCode }
65+
return result
6666
}
6767

6868
const onDirectoryScan = async () => {

tests/command.dev.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,5 +1780,28 @@ export const handler = async function () {
17801780
})
17811781
})
17821782
})
1783+
1784+
test(testName(`returns headers set by function`, args), async (t) => {
1785+
await withSiteBuilder('site-with-function-with-custom-headers', async (builder) => {
1786+
await builder
1787+
.withFunction({
1788+
pathPrefix: 'netlify/functions',
1789+
path: 'custom-headers.js',
1790+
handler: async () => ({
1791+
statusCode: 200,
1792+
body: '',
1793+
headers: { 'single-value-header': 'custom-value' },
1794+
multiValueHeaders: { 'multi-value-header': ['custom-value1', 'custom-value2'] },
1795+
}),
1796+
})
1797+
.buildAsync()
1798+
1799+
await withDevServer({ cwd: builder.directory, args }, async (server) => {
1800+
const response = await got(`${server.url}/.netlify/functions/custom-headers`)
1801+
t.is(response.headers['single-value-header'], 'custom-value')
1802+
t.is(response.headers['multi-value-header'], 'custom-value1, custom-value2')
1803+
})
1804+
})
1805+
})
17831806
})
17841807
/* eslint-enable require-await */

0 commit comments

Comments
 (0)