Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FQDN not working for single level parent domains #39

Open
petrosoft-fi opened this issue Apr 14, 2023 · 1 comment
Open

FQDN not working for single level parent domains #39

petrosoft-fi opened this issue Apr 14, 2023 · 1 comment

Comments

@petrosoft-fi
Copy link

petrosoft-fi commented Apr 14, 2023

Description of the bug
The SvelteKit adapter for AWS does not support using top-level domains (e.g., domain.com) as FQDN values. It only works correctly with subdomains (e.g., subdomain.domain.com) and third level domains (e.g. domain.co.uk).

In the current production version, the domainName variable incorrectly receives the value "com" when using "google.com" as an FQDN. Instead, it should be assigned the correct value, which in this case is "google.com".

Steps to reproduce the behavior:

  1. Set up a project using the SvelteKit adapter for AWS.
  2. Set the FQDN value to a top-level domain (e.g., domain.com).
  3. Deploy the project using AWS CDK.
  4. Encounter the error: "[Error at /sveltekit-adapter-aws-webapp] Found zones: [] for dns:com, privateZone:undefined, vpcId:undefined, but wanted exactly 1 zone"

Expected behavior
The adapter should work correctly with top-level domains, third level domains and subdomains as FQDN values.

Additional context
A potential fix for this issue is to modify the adapter-stack.js file to handle both second-level top-level domains (e.g., domain.co.uk) and regular top-level domains (e.g., domain.com):

const domainParts = ((_b = process.env.FQDN) === null || _b === void 0 ? void 0 : _b.split('.')) || [];
const isSecondLevelTLD = domainParts.length >= 3 && domainParts[domainParts.length - 2].length === 2;
const domainName = domainParts.slice(isSecondLevelTLD ? -3 : -2).join('.');

This code works as follows:

  1. It splits the FQDN string into an array of domain parts by splitting it on the period character (.).
  2. It checks if the domain has a second-level top-level domain (TLD) by checking if there are at least 3 domain parts and if the second last part of the domain has a length of 2 characters (e.g., co in domain.co.uk).
  3. It constructs the main domain by slicing the domainParts array. If the domain has a second-level TLD, it takes the last three parts of the array; otherwise, it takes the last two parts. Finally, it joins the resulting array back into a string using the period character (.).

With this code, the main domain should be correctly determined for cases like www.domain.com, domain.com, domain.co.uk, and subdomain.domain.co.uk.

@Tylermarques
Copy link

Confirming that I see the same behaviour.

When attempting to deploy with a top level domain I get the error Found zones: [] for dns:com, privateZone:undefined, vpcId:undefined, but wanted exactly 1 zone which lead me to this same conclusion. replacing my FQDN with www.mydomain.com fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants