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

Use single Gatsby app to deploy localized sites across domains. #5330

Closed
scnroy opened this issue May 8, 2018 · 12 comments
Closed

Use single Gatsby app to deploy localized sites across domains. #5330

scnroy opened this issue May 8, 2018 · 12 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@scnroy
Copy link
Contributor

scnroy commented May 8, 2018

As I understand it, the i18n pattern that I’ve seen for Gatsby allows you to toggle between different locales on the same path via the app’s internal routing system:

  • domain.com/site/es
  • domain.com/site/en

I'm trying to figure out how to, at build, churn out a whole site per locale so that we can deploy each at its own country-specific domain:

  • domain.com/site
  • domain.es/site
  • domain.fr/site

The imagined output is similar to #2189 (multiple public folders—public_en-US public_en-UK ...), instead, there's a single src folder that would be locale-aware and query for data accordingly during each build. Could this be accomplished with a plugin or would this be an enhancement?

This project has been a godsend, thanks to everyone for all the work ❤️

@m-allanson m-allanson added the type: question or discussion Issue discussing or asking a question about Gatsby label May 9, 2018
@m-allanson
Copy link
Contributor

@scnroy this sounds similar to #5270 and #2335, is there anything in those issues that helps?

@scnroy
Copy link
Contributor Author

scnroy commented May 9, 2018

#5270 could help, since we'd likely be able to use the same JS bundle for each locale, but i'm not sure if it gets to the i18n piece.

After thinking about it more, it seems as though #4050 may get me going in the right direction, where we pass in a locale and use it as an argument in a graphql query.

@scnroy scnroy closed this as completed May 9, 2018
@kitos
Copy link
Contributor

kitos commented Oct 15, 2019

I am still interested in this.
My team is currently working on migration of our app from nextjs to gatsby (some pages were already moved). We have several markets on different domains: tourlane.de, tourlane.com, ... and we have to host them as a separate applications in netlify, which is not ideal, since we have to manage 5 apps now.

What I would prefer to do is to build pages for all markets within a single app.

I tried to archive this by appending /${market}/ prefix to pages urls and then cut it off using netlify rewrites:

  • build
    /en/africa
    /de/afrika
    ...
  • rewrite
    tourlane.com/* /en/:splat 200
    tourlane.de/* /de/:splat 200

And this works fine on netlify side, but for gatsby /afrika is still /de/afrika, so it changes url on the client. Probably there are some other difficulties (I didn't investigated properly).

I wonder if somebody else has similar issue and found the solution (other than using separate applications 😃 ). Since using domains instead of subfolders is pretty popular approach.

@kitos kitos reopened this Oct 15, 2019
@scnroy
Copy link
Contributor Author

scnroy commented Oct 17, 2019

For what it's worth, we never found a good solution here. Our workaround has been a little node script that runsgatsby build once for each domain, then moves and renames the generated public folder into a final dist folder.
In some cases, we're running gatsby build 18 times in a row, which takes ~45 min.

@oowowaee
Copy link

Facing this issue right now - all the other pages within my app are fine (I am using the localized slugs for those pages, so the paths are different), but I am trying to rewrite domain1.com to domain2.com/spanish. Everything works fine on the netlify side, but unfortunately gatsby updates the url in the navbar to domain1.com/spanish.

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Nov 7, 2019
@gatsbot
Copy link

gatsbot bot commented Nov 7, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@gatsbot
Copy link

gatsbot bot commented Nov 18, 2019

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community!

@gatsbot gatsbot bot closed this as completed Nov 18, 2019
@genert
Copy link

genert commented Feb 3, 2020

@kitos Did you manage to figure this out?

@iriepixel
Copy link

@scnroy Hi, did you find an answer to your issue? I have the same problem.

@moigonzalez
Copy link

Hey, I managed to have several domains (*.com, *.es, *.uk...) by disabling client side routing.

I followed this issue: #4337 and the redirect and was gone after adding this plugin: https://github.com/wardpeet/gatsby-plugin-static-site

Hope it helps!

@HashemKhalifa
Copy link

exports.onPreBootstrap = ({ store }) => {
  const { program } = store.getState()
  const filePath = path.join(program.directory, '.cache', 'production-app.js')

  const code = fs.readFileSync(filePath, {
    encoding: `utf-8`,
  })

  const newCode = code.replace(
    `const { pagePath, location: browserLoc } = window`,
    `const { pagePath } = window
    let { location: browserLoc } = window

    if (window.parent.location !== browserLoc) {
      browserLoc = {
        pathname: pagePath
      }
    }
  `
  )

  fs.writeFileSync(filePath, newCode, `utf-8`)
}

that also works for me without using a plugin.

@happimaker
Copy link

I am using Gatsby, Contentful for delivery APIs, and deployed on Netlify.
So I made several brands for its location e.g. Los Angeles, Irvine, Palm Desert, etc.
And the locations are own domains such as losangeles.mybrand.com, irvine.mybrand.com, etc.
Then how to run website refer to its location, get the current domain, and show entries of the current brand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

9 participants