Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Forked from cardoni/env.js
Created October 29, 2017 05:20
Show Gist options
  • Save DavidWells/8d2e89a90265c9b4c4f75100a4f3f29a to your computer and use it in GitHub Desktop.
Save DavidWells/8d2e89a90265c9b4c4f75100a4f3f29a to your computer and use it in GitHub Desktop.
serverless custom domain setup
// eslint-disable-next-line import/no-extraneous-dependencies
const { argv } = require('yargs');
let { stage = 'dev' } = argv;
module.exports.getDomainName = () => new Promise((resolve, reject) => {
stage = `${stage}`.toLowerCase();
if (!stage || stage == null || stage === 'dev') {
return resolve('dev-api.yourdomain.com');
}
if (stage === 'int') {
return resolve('int-api.yourdomain.com');
}
if (stage === 'prod') {
return resolve('api.yourdomain.com');
}
return reject();
});
module.exports.getAPIBasePath = () => new Promise((resolve, reject) => {
// eslint-disable-next-line global-require
const existingServiceName = require('./package.json').name;
const apiServiceName = existingServiceName.replace(/-service/, '').trim();
if (!apiServiceName || apiServiceName == null) {
return reject();
}
return resolve(apiServiceName);
});
customDomain:
basePath: ${file(./env.js):getAPIBasePath}
domainName: ${file(./env.js):getDomainName}
stage: ${self:custom.service.STAGE}
certificateName: "*.yourdomain.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment