Skip to content

Commit

Permalink
feat: export requestToEvent util
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Jan 12, 2022
1 parent b6f32d0 commit a2f4fed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-pants-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'presta': patch
---

Export requestToEvent util
2 changes: 1 addition & 1 deletion packages/presta/lib/__tests__/requestToEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test('requestToEvent', async () => {
rawUrl: '/',
path: '/',
httpMethod: 'GET',
headers: { 'client-ip': '0.0.0.0' },
headers: {},
multiValueHeaders: {},
rawQuery: '',
queryStringParameters: {},
Expand Down
1 change: 1 addition & 0 deletions packages/presta/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { Config, Options } from './config'
export { HookPostBuildPayload, HookBuildFilePayload } from './createEmitter'
export { createPlugin, PluginInit, Plugin, PluginInterface } from './plugins'
export { getRouteParams as parsePathParameters } from './getRouteParams'
export { requestToEvent } from './requestToEvent'

/*
* for use in prod functions
Expand Down
11 changes: 5 additions & 6 deletions packages/presta/lib/requestToEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export function getQueryStringParameters(query: string) {
return { queryStringParameters, multiValueQueryStringParameters }
}

/**
* Generic util. This is now exported.
*
* TODO extract this?
*/
export async function requestToEvent(req: http.IncomingMessage): Promise<Event> {
const { url: path = '', method } = req
const { headers, multiValueHeaders } = normalizeHeaders(req.headers)
Expand All @@ -63,12 +68,6 @@ export async function requestToEvent(req: http.IncomingMessage): Promise<Event>
const rawQuery = parseUrl(path).query || ''
const { queryStringParameters, multiValueQueryStringParameters } = getQueryStringParameters(rawQuery)

/**
* Just fake this locally
* @see https://github.com/netlify/cli/blob/27bb7b9b30d465abe86f87f4274dd7a71b1b003b/src/utils/serve-functions.js#L208
*/
headers['client-ip'] = '0.0.0.0'

return {
rawUrl: path,
path,
Expand Down

0 comments on commit a2f4fed

Please sign in to comment.