From 95e9082f6639f321e9fada7d6d9102a0eb9abca6 Mon Sep 17 00:00:00 2001 From: Richard Tan Date: Tue, 26 May 2020 08:12:31 +1000 Subject: [PATCH 1/4] Readd to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 862ca38af..a5fd33ec2 100644 --- a/README.md +++ b/README.md @@ -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 From 8b8beaa01e2d1039054287b1d49a182a37272f35 Mon Sep 17 00:00:00 2001 From: Richard Tan Date: Tue, 26 May 2020 08:42:13 +1000 Subject: [PATCH 2/4] Add prefix to paths --- README.md | 2 +- src/events/http/HttpServer.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a5fd33ec2..093da96d0 100644 --- a/README.md +++ b/README.md @@ -105,7 +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: '/' +--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 diff --git a/src/events/http/HttpServer.js b/src/events/http/HttpServer.js index 9d26f6305..af2d3e4cd 100644 --- a/src/events/http/HttpServer.js +++ b/src/events/http/HttpServer.js @@ -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) @@ -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) } From a5ab194b3cda45c2cae23d5fb4ffd7463363555c Mon Sep 17 00:00:00 2001 From: Richard Tan Date: Tue, 26 May 2020 08:57:06 +1000 Subject: [PATCH 3/4] Add default --- src/config/defaultOptions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/defaultOptions.js b/src/config/defaultOptions.js index 20cc05b73..1da5b7404 100644 --- a/src/config/defaultOptions.js +++ b/src/config/defaultOptions.js @@ -16,6 +16,7 @@ export default { noPrependStageInUrl: false, noAuth: false, noTimeout: false, + prefix: '', printOutput: false, resourceRoutes: false, useChildProcesses: false, From de32a376d6c3cca2f9faf2ae5cdfca2d16ac441f Mon Sep 17 00:00:00 2001 From: Richard Tan Date: Tue, 26 May 2020 08:59:12 +1000 Subject: [PATCH 4/4] Added prefix to commandOptions --- src/config/commandOptions.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/config/commandOptions.js b/src/config/commandOptions.js index b93c0076e..9ee42e8ab 100644 --- a/src/config/commandOptions.js +++ b/src/config/commandOptions.js @@ -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.', },