Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ serverless webpack serve
Options are:

- `--port` or `-p` (optional) The local server port. Defaults to `8000`
- `--pathPrefix` or `-x` (optional) Add stage as a prefix to all path routes.
Defaults to value of `provider.stage` defined in `serverless.yml`, which defaults to `dev`

The `serve` command will automatically look for the local `serverless.yml` and serve
all the `http` events. For example this configuration will generate a GET enpoint:
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class ServerlessWebpack {
usage: 'The local server port',
shortcut: 'p',
},
stagePrefix: {
usage: 'Add stage as a prefix to all path routes',
shortcut: 'x',
},
},
},
},
Expand Down
5 changes: 3 additions & 2 deletions lib/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ module.exports = {
for (let httpEvent of funcConf.events) {
const method = httpEvent.method.toLowerCase();
let endpoint = `/${httpEvent.path}`;
if (this.options.stage) {
endpoint = `/${this.options.stage}${endpoint}`;
if (this.options.stagePrefix) {
const stage = this.options.stage ? this.options.stage : this.serverless.service.provider.stage
endpoint = `/${stage}${endpoint}`;
}
const path = endpoint.replace(/\{(.+?)\}/g, ':$1');
let handler = this._handlerBase(funcConf, httpEvent);
Expand Down