#One GitHub project, two deploys on two separate domains

6 messages · Page 1 of 1 (latest)

sand coral
#

I am attempting to build a multilingual site hosted on two separate TLDs. Is there a way to deploy the same code to two hosts or two hosting instances of the same host, assigned to separate TLDs, and make the language distinction from the TLD itself or from environment variables, while keeping the codebase singular and the deploy synchronized?

pure robinBOT
#

Hi @sand coral. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Astro supports deploying the same codebase to multiple hosts or domains, and you can distinguish site behavior (such as language) using environment variables or configuration. Here’s how you can approach your scenario based on the documentation:

1. Single Codebase, Multiple Deployments

You can keep a single GitHub repository and set up multiple deployment workflows (e.g., using GitHub Actions) to deploy to different hosts or different instances of the same host. Each deployment can use its own environment variables or configuration files to set the domain and language preferences.

For example, when deploying to GitHub Pages with a custom domain, you set the site option in astro.config.mjs to your domain, and you can omit the base option if deploying to the root. You can create a public/CNAME file for each deployment to specify the custom domain. For two TLDs, you would run two separate deploy workflows, each with its own configuration and CNAME file for the respective domain. The documentation shows how to set the site option and use a custom domain for GitHub Pages, but the same principle applies to other hosts as well Deploy to GitHub Pages.

2. Using Environment Variables

Astro supports environment variables via .env files or CI/CD environment settings. You can use these to control language or domain-specific behavior at build or runtime. For example, you could set a DEFAULT_LANGUAGE or SITE_DOMAIN variable for each deployment, and reference it in your code using import.meta.env Using environment variables.

#

You can have different .env.production files for each deployment, or set environment variables in your CI/CD pipeline. This allows you to change site behavior (like default language) based on the deployment target.

3. Language Distinction by TLD

While the documentation does not explicitly describe using the TLD to determine language, you can implement this by setting an environment variable or configuration value per deployment (as above), or by detecting the domain at runtime (if using SSR). For static sites, the distinction would need to be made at build time via environment variables.

4. Keeping Deploys Synchronized

By using GitHub Actions or another CI/CD system, you can trigger both deploys from the same repository and branch, ensuring both sites are always in sync with your codebase Configure a GitHub Action.


Summary:
Yes, you can deploy the same Astro codebase to two different domains, using environment variables or configuration to distinguish language or other settings per domain. You’ll need to set up separate deploy workflows for each domain, and manage environment variables or config files to control site behavior. The documentation provides guidance on custom domains, environment variables, and CI/CD deploys, but does not provide a ready-made solution for TLD-based language detection—you would need to implement that logic yourself using the tools described above.

If you need more specific examples or code, let me know!

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@sand coral Kapa.ai is still learning and improving, please let me know how I did by reacting below.

sand coral
#

<@&1095491216776380548> can you check whether anyone in the community has done this in the past, and link to the Discord message anywhere on this server?