serverless-components / express

⚡ Take existing Express.js apps and host them easily on cheap, auto-scaling, serverless infrastructure (AWS Lambda and AWS HTTP API).
https://serverless.com/components
Apache License 2.0
375 stars 34 forks source link

domain setting fails with brazilian domains (.com.br) #50

Closed gilsoncav closed 3 years ago

gilsoncav commented 3 years ago

When setting the yml with this option:

inputs:
  domain: api.mydomain.com.br

it doesn't behave well due to this method that wrongly gets the naked domain:

/*
 * Extracts the naked second level domain (ie. serverless.com) from
 * the provided domain or subdomain (ie. api.serverless.com)
 *
 * @param ${string} domain - the domain input that the user provided
 */
const getNakedDomain = (domain) => {
  if (!domain) {
    return null;
  }
  const domainParts = domain.split('.');
  const topLevelDomainPart = domainParts[domainParts.length - 1];
  const secondLevelDomainPart = domainParts[domainParts.length - 2];
  return `${secondLevelDomainPart}.${topLevelDomainPart}`;
};

Maybe using a regex based matching would be a better approach.

pdemich commented 3 years ago

Fix for this issue can be ported from the website component:

const getNakedDomain = (domain) => {
  const parsedDomain = parseDomain(domain)

  if (!parsedDomain.topLevelDomains) {
    throw new Error(`"${domain}" is not a valid domain.`)
  }

  const nakedDomain = `${parsedDomain.domain}.${parsedDomain.topLevelDomains.join('.')}`
  return nakedDomain
}
eahefnawy commented 3 years ago

This should now be fixed and published.