Skip to content

Commit

Permalink
fix: better server side protocol detection (fixes #123)
Browse files Browse the repository at this point in the history
Use module that detects protocol used in more accurate way.
  • Loading branch information
rchl committed Jun 18, 2019
1 parent 5e0c8f1 commit 8cb3eb6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"acorn-dynamic-import": "^4.0.0",
"acorn-walk": "^6.1.1",
"cookie": "^0.4.0",
"is-https": "^1.0.0",
"js-cookie": "^2.2.0",
"vue-i18n": "^8.11.2",
"vue-i18n-extensions": "^0.2.1"
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/routing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './middleware';
import './middleware'
import Vue from 'vue'
import isHTTPS from 'is-https'

const routesNameSeparator = '<%= options.routesNameSeparator %>'

Expand Down Expand Up @@ -73,11 +74,11 @@ function switchLocalePathFactory (i18nPath) {
const lang = this[i18nPath].locales.find(l => l[LOCALE_CODE_KEY] === locale)
if (lang && lang[LOCALE_DOMAIN_KEY]) {
let protocol
if (!process.browser) {
if (process.server) {
const { req } = this.$options._parentVnode.ssrContext
protocol = req.secure ? 'https' : 'http'
protocol = isHTTPS(req) ? 'https' : 'http'
} else {
protocol = window.location.href.split(':')[0]
protocol = window.location.protocol.split(':')[0]
}
path = protocol + '://' + lang[LOCALE_DOMAIN_KEY] + path
} else {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6713,6 +6713,11 @@ is-glob@^4.0.0, is-glob@^4.0.1:
dependencies:
is-extglob "^2.1.1"

is-https@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-https/-/is-https-1.0.0.tgz#9c1dde000dc7e7288edb983bef379e498e7cb1bf"
integrity sha512-1adLLwZT9XEXjzhQhZxd75uxf0l+xI9uTSFaZeSESjL3E1eXSPpO+u5RcgqtzeZ1KCaNvtEwZSTO2P4U5erVqQ==

is-installed-globally@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/is-installed-globally/-/is-installed-globally-0.1.0.tgz#0dfd98f5a9111716dd535dda6492f67bf3d25a80"
Expand Down

0 comments on commit 8cb3eb6

Please sign in to comment.