Skip to content

Commit

Permalink
Merge pull request #988 from chardos/master
Browse files Browse the repository at this point in the history
feat(prefixes): Bring back prefix option
  • Loading branch information
dherault committed May 27, 2020
2 parents e1b0b56 + de32a37 commit d45b203
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -105,6 +105,7 @@ All CLI options are optional:
--noPrependStageInUrl Don't prepend http routes with the stage.
--noAuth Turns off all authorizers
--noTimeout -t Disables the timeout feature.
--prefix -p Adds a prefix to every path, to send your requests to http://localhost:3000/[prefix]/[your_path] instead. Default: ''
--printOutput Turns on logging of your lambda outputs in the terminal.
--resourceRoutes Turns on loading of your HTTP proxy settings from serverless.yml
--useChildProcesses Run handlers in a child process
Expand Down
5 changes: 5 additions & 0 deletions src/config/commandOptions.js
Expand Up @@ -53,6 +53,11 @@ export default {
shortcut: 't',
usage: 'Disables the timeout feature.',
},
prefix: {
shortcut: 'p',
usage:
'Adds a prefix to every path, to send your requests to http://localhost:3000/prefix/[your_path] instead.',
},
printOutput: {
usage: 'Outputs your lambda response to the terminal.',
},
Expand Down
1 change: 1 addition & 0 deletions src/config/defaultOptions.js
Expand Up @@ -16,6 +16,7 @@ export default {
noPrependStageInUrl: false,
noAuth: false,
noTimeout: false,
prefix: '',
printOutput: false,
resourceRoutes: false,
useChildProcesses: false,
Expand Down
9 changes: 9 additions & 0 deletions src/events/http/HttpServer.js
Expand Up @@ -256,6 +256,11 @@ export default class HttpServer {
hapiPath = `/${stage}${hapiPath}`
}

// add prefix to path
if (this.#options.prefix) {
hapiPath = `/${this.#options.prefix}${hapiPath}`
}

// but must not end with '/'
if (hapiPath !== '/' && hapiPath.endsWith('/')) {
hapiPath = hapiPath.slice(0, -1)
Expand Down Expand Up @@ -890,6 +895,10 @@ export default class HttpServer {
hapiPath = `/${stage}${hapiPath}`
}

if (this.#options.prefix) {
hapiPath = `/${this.#options.prefix}${hapiPath}`
}

if (hapiPath !== '/' && hapiPath.endsWith('/')) {
hapiPath = hapiPath.slice(0, -1)
}
Expand Down

0 comments on commit d45b203

Please sign in to comment.