Skip to content

fix(command-dev): pass full lambda-local result functions server #2901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/functions/runtimes/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ const invokeFunction = async ({ context, event, func, timeout }) => {
// If a function builder has defined a `buildPath` property, we use it.
// Otherwise, we'll invoke the function's main file.
const lambdaPath = (func.buildData && func.buildData.buildPath) || func.mainFile
const { body, statusCode } = await lambdaLocal.execute({
const result = await lambdaLocal.execute({
clientContext: context,
event,
lambdaPath,
timeoutMs: timeout * SECONDS_TO_MILLISECONDS,
verboseLevel: 3,
})

return { body, statusCode }
return result
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can also pass just the stuff we're expecting.

}

const onDirectoryScan = async () => {
Expand Down
23 changes: 23 additions & 0 deletions tests/command.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1780,5 +1780,28 @@ export const handler = async function () {
})
})
})

test(testName(`returns headers set by function`, args), async (t) => {
await withSiteBuilder('site-with-function-with-custom-headers', async (builder) => {
await builder
.withFunction({
pathPrefix: 'netlify/functions',
path: 'custom-headers.js',
handler: async () => ({
statusCode: 200,
body: '',
headers: { 'single-value-header': 'custom-value' },
multiValueHeaders: { 'multi-value-header': ['custom-value1', 'custom-value2'] },
}),
})
.buildAsync()

await withDevServer({ cwd: builder.directory, args }, async (server) => {
const response = await got(`${server.url}/.netlify/functions/custom-headers`)
t.is(response.headers['single-value-header'], 'custom-value')
t.is(response.headers['multi-value-header'], 'custom-value1, custom-value2')
})
})
})
})
/* eslint-enable require-await */