I18n-module: Server side rendered locale switching links will always start with http

Created on 31 Aug 2018  路  9Comments  路  Source: nuxt-community/i18n-module

Version

v5.2.1

Reproduction link

-

Steps to reproduce

-

What is expected ?

-

What is actually happening?

-

Additional comments?

In https://github.com/nuxt-community/nuxt-i18n/blob/e2aa687083873b6cb20b29beb044db8572e223cf/src/plugins/routing.js#L56 req.secure is used, which is only defined in Express, but SSR context only provides Node's http.IncomingMessage which does not contain such property, resulting in any of the links generated by switchLocalePath server side to start with http.

This bug report is available on Nuxt community (#c128)

Most helpful comment

Checking protocol can be easily done for this module:

https://github.com/nuxt-community/is-https

Which is already used by sitemap module

All 9 comments

A PR would be more then welcome :)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

It does not seem a very easy fix as the method that determines req.secure is quite complex. Porting all of that logic over to this plugin is not very intuitive. I would certainly contribute, if I knew what the suitable solution was.

Would it be possible to check the requested URL through req? :thinking:

Not if the hosted application is behind a reverse proxy.

The logic is not that big (https://github.com/expressjs/express/blob/b8e50568af9c73ef1ade434e92c60d389868361d/lib/request.js#L306) but:

  • it requires external proxy-addr dependency
  • while in most cases it should do the right thing on its own, in specific setups users would need to provide configuration for that logic (same as trust proxy in expressjs provides here https://expressjs.com/en/4x/api.html#trust.proxy.options.table)

It feels kinda wrong to have to have all that in nuxt-i18n itself. It would be better if nuxt itself took care of those things. I wished nuxt used expressjs instead of connect...

It feels kinda wrong to have to have all that in nuxt-i18n itself. It would be better if nuxt itself took care of those things.

That's what I am thinking as well.

Checking protocol can be easily done for this module:

https://github.com/nuxt-community/is-https

Which is already used by sitemap module

@pi0 thanks. This is exactly what is needed. Including it in this package should be a no-brainer too...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnboylesingfield picture johnboylesingfield  路  17Comments

pi0 picture pi0  路  18Comments

varna picture varna  路  14Comments

koteezy picture koteezy  路  16Comments

vodnicearv picture vodnicearv  路  20Comments