question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using http instead of https locally with localized domains

See original GitHub issue

What version of Next.js are you using?

10.2

What version of Node.js are you using?

14.16.1

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

next start

Describe the Bug

I have a Next.js application that uses two different domains for different languages. English uses .com and German uses .de. When I upgraded to Next.js 10, I rewrote the entire mechanism to use the built-in localization feature that supports multiple domains out of the box which is absolutely awesome and works like a charm in production.

However, I have had problems locally with development since then. When I click on a link, it automatically redirects to https which I am not using for development which of course leads to the browser not being able to connect to the page. I use the following domains for local development which, of course, are set up in /etc/hosts:

127.0.0.1       en.localhost
127.0.0.1       de.localhost

Of course, I can access the application over localhost without the subdomain and the links work perfectly fine, but then I have no way to distinguish between the languages for development. Anyone have any suggestions on how to work around this? Is this a bug that I should report?

Expected Behavior

I expect to be able to disable https for local development regardless of the domain. Perhaps it would be a good idea to make it settable in the next.config.js file or as an env variable.

To Reproduce

  1. Create a Next.js application
  2. Set up multiple locales using multiple domains as described in the docs: https://nextjs.org/docs/advanced-features/i18n-routing#locale-strategies
  3. Add domains for local development with a config similar to this:
domains: [
  {
    domain: process.env.NODE_ENV === 'development' ? 'en.localhost' : 'somedomain.com',
    defaultLocale: 'en',
  },
  {
    domain: process.env.NODE_ENV === 'development' ? 'de.localhost' : 'irgendeinedomain.de'
    defaultLocale: 'de',
  }
]
  1. Add the local domains to your hosts file:
127.0.0.1       en.localhost
127.0.0.1       de.localhost
  1. Create at least 2 pages with links between them using the next/link component.
  2. Click on a link.
  3. The browser navigates to the page, but with https.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
eiskalteschattencommented, Jun 29, 2021

I wish I had read your comment above more closely. As soon as I removed the port from the hostnames, the redirect loop stops. 😩 That seems to have fixed the problem.

2reactions
ijjkcommented, Jun 18, 2021

If you want to use http instead of https when testing locally, you can set http: true on the local domain e.g.

module.exports = {
  i18n: {
    locales: ['en','fr'],
    defaultLocale: 'en',
    domains: [{ http: true, domain: 'example.com', locale: 'en' }]
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use HTTPS for local development - web.dev
If you open your locally running site in your browser using HTTPS, your browser will check the certificate of your local development server....
Read more >
Using HTTPS in Your Development Environment - Auth0
Learn why you should use HTTPS even for development and how to set up your localhost with that secure protocol.
Read more >
Setting up https with a valid certificate for a local domain
You can either use http://localhost or you can use a local domain (e.g. ... With this in place we can move on and...
Read more >
The Complete Guide To Switching From HTTP To HTTPS
The encrypted channel is created using the Transport Layer Security (TLS) protocol, previously called Secure Socket Layer (SSL).
Read more >
How to get HTTPS working on your local development ...
This poses a problem for developers who use a local development environment because all of them run on http://localhost out-of-the-box.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found