Load different json depending on domain (Eleventy)

Hi,

I’m new to javascript and static sites. Coming from the PHP world the question might be stupid in this context, but I have no luck in googling.

I’m using Eleventy (the eleventyone template) to build a website.
I want to add multiple domains to the same Netlify website, and depending on which domain is visited a different json file should be loaded. The json file will basically hold all text for the site.

Pseudo-code to explain my intentions:

<script>
var domain = window.location.hostname;
</script>
<ul>
{%- for item in domain -%}
    <li>{{ item.name }}</li>
{%- endfor -%}
 </ul>

This should load the appropriate file from the _data/ directory, e.g. _data/dev/examplecom.json.

I also tried to define the hostname using a Netlify function, but window.location.hostname yields the error window is not defined.

Is what I’m trying to do at all possible for a static site on Netlify?

Hi @Elias, what you’re probably looking to do is implement a redirect rule based in your domain: Redirects and rewrites | Netlify Docs.

Something like this:

https://somedomain.com/_data/dev/main.json /_data/dev/somedomaincom.json 200
https://otherdomain.com/_data/dev/main.json /_data/dev/somedomaincom.json 200

That’s it! Thank you @Dennis