Skip to content

Commit

Permalink
fix: IE11 compatibility issue due to is-https package (#1138)
Browse files Browse the repository at this point in the history
Fixes #1137
  • Loading branch information
rchl authored Apr 7, 2021
1 parent 4bd8194 commit dcf43de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"@intlify/vue-i18n-loader": "^1.0.0",
"cookie": "^0.4.0",
"devalue": "^2.0.1",
"is-https": "^3.0.0",
"js-cookie": "^2.2.1",
"klona": "^2.0.4",
"lodash.merge": "^4.6.2",
Expand Down
30 changes: 29 additions & 1 deletion src/templates/utils-common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Cookie from 'cookie'
import JsCookie from 'js-cookie'
import isHTTPS from 'is-https'

/** @typedef {import('../../types/internal').ResolvedOptions} ResolvedOptions */

Expand Down Expand Up @@ -134,6 +133,35 @@ export function getDomainFromLocale (localeCode, req, { normalizedLocales }) {
console.warn(formatMessage(`Could not find domain name for locale ${localeCode}`))
}

/**
* Determines if a server-side request is using HTTPS.
*
* @param {import('http').IncomingMessage} req
* @param {Boolean} [trustProxy=true]
* @return {Boolean | undefined}.
*/
function isHTTPS (req, trustProxy = true) {
// Check x-forwarded-proto header
const _xForwardedProto = (trustProxy && req.headers) ? req.headers['x-forwarded-proto'] : undefined
const protoCheck = typeof _xForwardedProto === 'string' ? _xForwardedProto.includes('https') : undefined
if (protoCheck) {
return true
}

const socket = /** @type {import('tls').TLSSocket} */(req.socket)
const _encrypted = socket ? socket.encrypted : undefined
const encryptedCheck = _encrypted !== undefined ? _encrypted === true : undefined
if (encryptedCheck) {
return true
}

if (protoCheck === undefined && encryptedCheck === undefined) {
return undefined
}

return false
}

/**
* Get locale code that corresponds to current hostname
*
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7061,11 +7061,6 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
dependencies:
is-extglob "^2.1.1"

is-https@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/is-https/-/is-https-3.0.2.tgz#4d24e002e47edd3f1b07f14bc722433354ccba49"
integrity sha512-jFgAKhbNF7J+lTMJxbq5z9bf1V9f8rXn9mP5RSY2GUEW5M0nOiVhVC9dNra96hQDjGpNzskIzusUnXwngqmhAA==

is-installed-globally@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/is-installed-globally/-/is-installed-globally-0.4.0.tgz#9a0fd407949c30f86eb6959ef1b7994ed0b7b520"
Expand Down

0 comments on commit dcf43de

Please sign in to comment.