From 2a17c99145c280b7304691396b8e009056054ae5 Mon Sep 17 00:00:00 2001 From: Max <49632507+maxm86545@users.noreply.github.com> Date: Sun, 15 Mar 2020 21:48:10 +0300 Subject: [PATCH] fix: remove forwardedHost option - make domain matching consistent on server/client (#630) --- docs/api/README.md | 6 ------ docs/es/api/README.md | 6 ------ docs/es/options-reference.md | 4 ---- docs/options-reference.md | 4 ---- src/helpers/constants.js | 1 - src/plugins/main.js | 2 -- src/templates/utils.js | 20 +------------------- types/nuxt-i18n.d.ts | 1 - 8 files changed, 1 insertion(+), 43 deletions(-) diff --git a/docs/api/README.md b/docs/api/README.md index 97e219c4b..6a7730014 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -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` diff --git a/docs/es/api/README.md b/docs/es/api/README.md index 4cd50ba31..98054eade 100644 --- a/docs/es/api/README.md +++ b/docs/es/api/README.md @@ -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` diff --git a/docs/es/options-reference.md b/docs/es/options-reference.md index 20352dcbd..ffba10dff 100644 --- a/docs/es/options-reference.md +++ b/docs/es/options-reference.md @@ -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: diff --git a/docs/options-reference.md b/docs/options-reference.md index 8bc750d63..30bdc935c 100644 --- a/docs/options-reference.md +++ b/docs/options-reference.md @@ -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: diff --git a/src/helpers/constants.js b/src/helpers/constants.js index ea346d183..6de39e42a 100644 --- a/src/helpers/constants.js +++ b/src/helpers/constants.js @@ -41,7 +41,6 @@ exports.DEFAULT_OPTIONS = { fallbackLocale: null }, differentDomains: false, - forwardedHost: false, seo: false, baseUrl: '', vuex: { diff --git a/src/plugins/main.js b/src/plugins/main.js index 9d0b4db42..79df7fe17 100644 --- a/src/plugins/main.js +++ b/src/plugins/main.js @@ -8,7 +8,6 @@ import { defaultLocale, detectBrowserLanguage, differentDomains, - forwardedHost, lazy, localeCodes, locales, @@ -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 diff --git a/src/templates/utils.js b/src/templates/utils.js index 4e9333076..79f666b42 100755 --- a/src/templates/utils.js +++ b/src/templates/utils.js @@ -129,24 +129,6 @@ 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 @@ -154,7 +136,7 @@ const getHostname = req => ( * @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) { diff --git a/types/nuxt-i18n.d.ts b/types/nuxt-i18n.d.ts index c9f8eca03..29fdaf597 100644 --- a/types/nuxt-i18n.d.ts +++ b/types/nuxt-i18n.d.ts @@ -46,7 +46,6 @@ declare namespace NuxtVueI18n { defaultLocale?: null | Locale locales?: Array differentDomains?: boolean - forwardedHost?: boolean onLanguageSwitched?: (oldLocale: string, newLocale: string) => void }