Skip to content

Commit

Permalink
Merge pull request #1030 from collabsoft-net/master
Browse files Browse the repository at this point in the history
fix greedy path for proxy
  • Loading branch information
dherault committed Jun 29, 2020
2 parents 8d10387 + 8128fda commit 7485bf3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
16 changes: 7 additions & 9 deletions src/events/http/HttpServer.js
Expand Up @@ -909,26 +909,24 @@ export default class HttpServer {
serverlessLog('Routes defined in resources:')

Object.entries(resourceRoutes).forEach(([methodId, resourceRoutesObj]) => {
const {
isProxy,
method,
path,
pathResource,
proxyUri,
} = resourceRoutesObj
const { isProxy, method, pathResource, proxyUri } = resourceRoutesObj

if (!isProxy) {
serverlessLog(
`WARNING: Only HTTP_PROXY is supported. Path '${pathResource}' is ignored.`,
)
return
}
if (!path) {
if (!pathResource) {
serverlessLog(`WARNING: Could not resolve path for '${methodId}'.`)
return
}

const hapiPath = generateHapiPath(path, this.#options, this.#serverless)
const hapiPath = generateHapiPath(
pathResource,
this.#options,
this.#serverless,
)
const proxyUriOverwrite = resourceRoutesOptions[methodId] || {}
const proxyUriInUse = proxyUriOverwrite.Uri || proxyUri

Expand Down
7 changes: 0 additions & 7 deletions src/events/http/parseResources.js
Expand Up @@ -145,10 +145,6 @@ function getIntegrationObj(methodObj) {
return methodObj.Properties.Integration
}

function templatePathToHapiPath(path) {
return path.replace('+', '')
}

function constructHapiInterface(pathObjects, methodObjects, methodId) {
// returns all info necessary so that routes can be added in index.js
const methodObj = methodObjects[methodId]
Expand All @@ -163,16 +159,13 @@ function constructHapiInterface(pathObjects, methodObjects, methodId) {
return {}
}

const path = templatePathToHapiPath(pathResource)

if (Integration.Type === APIGATEWAY_INTEGRATION_TYPE_HTTP_PROXY) {
proxyUri = Integration.Uri
}

return {
isProxy: !!proxyUri,
method,
path,
pathResource,
proxyUri,
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/generateHapiPath.js
Expand Up @@ -4,7 +4,7 @@ export default function generateHapiPath(path = '', options, serverless) {

if (!options.noPrependStageInUrl) {
const stage = options.stage || serverless.service.provider.stage
// prepend stage to path
// prepend the stage to path
hapiPath = `/${stage}${hapiPath}`
}

Expand Down

0 comments on commit 7485bf3

Please sign in to comment.