Skip to content

Commit

Permalink
feat: add stripBasePath for custom domain names
Browse files Browse the repository at this point in the history
  • Loading branch information
brettstack committed May 1, 2019
1 parent c746fb4 commit 3a5c7ed
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
1 change: 1 addition & 0 deletions __tests__/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function makeEvent (eventOverrides) {
const multiValueHeaders = Object.assign({}, baseEvent.multiValueHeaders, eventOverrides.multiValueHeaders)
const root = Object.assign({}, baseEvent, eventOverrides)
root.multiValueHeaders = multiValueHeaders
root.pathParameters.proxy = eventOverrides.path && eventOverrides.path.replace(/^\//, '')
return root
}

Expand Down
59 changes: 27 additions & 32 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,49 +116,44 @@ function configure ({
app: configureApp,
binaryMimeTypes: configureBinaryMimeTypes = [],
resolutionMode: configureResolutionMode = 'CONTEXT_SUCCEED',
_eventSource
} = {}) {
function _createServer ({
eventSource: configureEventSource,
eventFns: configureEventFns,
createServer: configureCreateServer = ({
app = configureApp,
binaryMimeTypes = configureBinaryMimeTypes
} = {}) {
return createServer({
app,
binaryMimeTypes
})
}

const _server = _createServer()

function _proxy ({
server = _server,
} = {}) => (createServer({
app,
binaryMimeTypes
})),
server: configureServer = configureCreateServer(),
proxy: configureProxy = ({
server = configureServer,
resolutionMode = configureResolutionMode,
event,
context,
callback,
eventSource = _eventSource
} = {}) {
return proxy({
server,
event,
context,
resolutionMode,
callback,
eventSource
})
}

const _handler = (event, context, callback) => _proxy({
eventSource = configureEventSource,
eventFns = configureEventFns
} = {}) => (proxy({
server,
event,
context,
resolutionMode,
callback,
eventSource,
eventFns
})),
handler: configureHhandler = (event, context, callback) => configureProxy({
event,
context,
callback
})

} = {}) {
return {
server: _server,
createServer: _createServer,
proxy: _proxy,
handler: _handler
server: configureServer,
createServer: configureCreateServer,
proxy: configureProxy,
handler: configureHhandler
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ function isContentTypeBinaryMimeType ({ contentType, binaryMimeTypes }) {

function getPathWithQueryStringParams ({
event,
pathname = event.path,
query = event.multiValueQueryStringParameters
query = event.multiValueQueryStringParameters,
// NOTE: Use `event.pathParameters.proxy` if available ({proxy+}); fall back to `event.path`
path = (event.pathParameters && event.pathParameters.proxy && `/${event.pathParameters.proxy}`) || event.path,
// NOTE: Strip base path for custom domains
stripBasePath = '',
replaceRegex = new RegExp(`^${stripBasePath}`)
}) {
return url.format({
pathname,
pathname: path.replace(replaceRegex, ''),
query
})
}
Expand Down

0 comments on commit 3a5c7ed

Please sign in to comment.