Skip to content

Commit

Permalink
Merge pull request #941 from RichiCoder1/master
Browse files Browse the repository at this point in the history
fix: fixup no prepend stage changes
  • Loading branch information
dherault committed Mar 25, 2020
2 parents 9803cb2 + 60dc55a commit ee26de3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/events/http/HttpServer.js
Expand Up @@ -278,6 +278,7 @@ export default class HttpServer {
method,
path: hapiPath,
server,
stage: this.#options.noPrependStageInUrl ? null : stage,
})

// If the endpoint has an authorization function, create an authStrategy for the route
Expand Down Expand Up @@ -346,7 +347,9 @@ export default class HttpServer {
url: request.url.href,
}

const requestPath = request.path.substr(`/${stage}`.length)
const requestPath = request.path.substr(
this.#options.noPrependStageInUrl ? 1 : `/${stage}`.length,
)

if (request.auth.credentials && request.auth.strategy) {
this.#lastRequestOptions.auth = request.auth
Expand Down Expand Up @@ -877,9 +880,12 @@ export default class HttpServer {

let hapiPath = path.startsWith('/') ? path : `/${path}`

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

if (hapiPath !== '/' && hapiPath.endsWith('/')) {
hapiPath = hapiPath.slice(0, -1)
Expand Down
7 changes: 4 additions & 3 deletions src/serverlessLog.js
Expand Up @@ -36,12 +36,13 @@ export function setLog(serverlessLogRef) {
// logs based on:
// https://github.com/serverless/serverless/blob/master/lib/classes/CLI.js

function logRoute(method, server, path, maxLength) {
function logRoute(method, server, path, maxLength, stage) {
const methodColor = colorMethodMapping.get(method) ?? peachpuff
const methodFormatted = method.padEnd(maxLength, ' ')

return `${methodColor(methodFormatted)} ${yellow.dim('|')} ${grey.dim(
server,
stage ? `${stage}/` : '',
)}${lime(path)}`
}

Expand All @@ -61,8 +62,8 @@ export function logRoutes(routeInfo) {
console.log(
boxen(
routeInfo
.map(({ method, path, server }) =>
logRoute(method, server, path, maxLength),
.map(({ method, path, server, stage }) =>
logRoute(method, server, path, maxLength, stage),
)
.join('\n'),
boxenOptions,
Expand Down

0 comments on commit ee26de3

Please sign in to comment.