Skip to content

Commit

Permalink
fix: remove forwardedHost option - make domain matching consistent on…
Browse files Browse the repository at this point in the history
… server/client (#630)
  • Loading branch information
maxm86545 committed Mar 15, 2020
1 parent bfdfc28 commit 2a17c99
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 43 deletions.
6 changes: 0 additions & 6 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ Instance of [VueI18n class](http://kazupon.github.io/vue-i18n/api/#vuei18n-class

Whether `differentDomains` option is enabled.

#### forwardedHost

- **Type**: `boolean`

Whether `forwardedHost` option is enabled.

#### beforeLanguageSwitch

- **Type**: `Function`
Expand Down
6 changes: 0 additions & 6 deletions docs/es/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ Instance of [VueI18n class](http://kazupon.github.io/vue-i18n/api/#vuei18n-class

Whether `differentDomains` option is enabled.

#### forwardedHost

- **Type**: `boolean`

Whether `forwardedHost` option is enabled.

#### beforeLanguageSwitch

- **Type**: `Function`
Expand Down
4 changes: 0 additions & 4 deletions docs/es/options-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ Aquí están todas las opciones disponibles al configurar el módulo y sus valor
// as an array of objects, each containing a domain key
differentDomains: false,

// If using different domains, set this to true to get hostname from X-Forwared-Host
// HTTP header instead of window.location
forwardedHost: false,

// If true, SEO metadata is generated for routes that have i18n enabled.
// Note that performance can suffer with this enabled and there might be compatibility
// issues with some plugins. Recommended way is to set up SEO as described in:
Expand Down
4 changes: 0 additions & 4 deletions docs/options-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ Here are all the options available when configuring the module and their default
// as an array of objects, each containing a domain key
differentDomains: false,

// If using different domains, set this to true to get hostname from X-Forwared-Host
// HTTP header instead of window.location
forwardedHost: false,

// If true, SEO metadata is generated for routes that have i18n enabled.
// Note that performance can suffer with this enabled and there might be compatibility
// issues with some plugins. Recommended way is to set up SEO as described in:
Expand Down
1 change: 0 additions & 1 deletion src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ exports.DEFAULT_OPTIONS = {
fallbackLocale: null
},
differentDomains: false,
forwardedHost: false,
seo: false,
baseUrl: '',
vuex: {
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
defaultLocale,
detectBrowserLanguage,
differentDomains,
forwardedHost,
lazy,
localeCodes,
locales,
Expand Down Expand Up @@ -192,7 +191,6 @@ export default async (context) => {
app.i18n.locales = locales
app.i18n.defaultLocale = defaultLocale
app.i18n.differentDomains = differentDomains
app.i18n.forwardedHost = forwardedHost
app.i18n.beforeLanguageSwitch = beforeLanguageSwitch
app.i18n.onLanguageSwitched = onLanguageSwitched
app.i18n.setLocaleCookie = setLocaleCookie
Expand Down
20 changes: 1 addition & 19 deletions src/templates/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,14 @@ export function isSameRoute (a, b) {
return false
}

/**
* Get x-forwarded-host
* @param {object} req
* @return {String} x-forwarded-host
*/
const getForwarded = req => (
process.client ? window.location.href.split('/')[2] : (req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host)
)

/**
* Get hostname
* @param {object} req
* @return {String} Hostname
*/
const getHostname = req => (
process.client ? window.location.href.split('/')[2] : req.headers.host
)

/**
* Get locale code that corresponds to current hostname
* @param {VueI18n} nuxtI18n Instance of VueI18n
* @param {object} req Request object
* @return {String} Locade code found if any
*/
export const getLocaleDomain = (nuxtI18n, req) => {
const hostname = nuxtI18n.forwardedHost ? getForwarded(req) : getHostname(req)
const hostname = process.client ? window.location.hostname : (req.headers['x-forwarded-host'] || req.headers.host)
if (hostname) {
const localeDomain = nuxtI18n.locales.find(l => l[LOCALE_DOMAIN_KEY] === hostname)
if (localeDomain) {
Expand Down
1 change: 0 additions & 1 deletion types/nuxt-i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ declare namespace NuxtVueI18n {
defaultLocale?: null | Locale
locales?: Array<Locale | LocaleObject>
differentDomains?: boolean
forwardedHost?: boolean
onLanguageSwitched?: (oldLocale: string, newLocale: string) => void
}

Expand Down

0 comments on commit 2a17c99

Please sign in to comment.