Skip to content
Merged
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
23 changes: 23 additions & 0 deletions src/definitionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ class DefinitionGenerator {
slashPath = `/${(event?.http?.path || event.httpApi?.path) ?? ""}`;
}

const basePath = this.getBasePath();

if (basePath) {
// append the base path so server is just the pure domain
slashPath = `/${basePath}${slashPath}`;
}

if (paths[slashPath]) {
Object.assign(paths[slashPath], path);
} else {
Expand All @@ -280,6 +287,22 @@ class DefinitionGenerator {
}
}

/**
* @description Retrieves the basePath value if the domain manager plugin is used, allowing the server URL to be just the plain domain. The `basePath` will be prepended to each Lambda HTTP path.
* @returns {string}
*/
getBasePath() {
const plugins = this.serverless.service.plugins || [];

let basePath = "";

if (plugins.includes("serverless-domain-manager")) {
basePath = this.serverless.service.custom.basePath || "";
}

return basePath;
}

createServers(servers) {
const serverDoc = servers;
const newServers = [];
Expand Down