Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prefixes): Bring back prefix option #988

Merged
merged 4 commits into from May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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