-
-
Save DavidWells/8d2e89a90265c9b4c4f75100a4f3f29a to your computer and use it in GitHub Desktop.
serverless custom domain setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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