Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: transpile is-https #1172

Merged
merged 2 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"@intlify/vue-i18n-loader": "^1.1.0",
"cookie": "^0.4.1",
"devalue": "^2.0.1",
"is-https": "^4.0.0",
"js-cookie": "^2.2.1",
"klona": "^2.0.4",
"lodash.merge": "^4.6.2",
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ export default function (moduleOptions) {
}
this.options.render.bundleRenderer.directives = this.options.render.bundleRenderer.directives || {}
this.options.render.bundleRenderer.directives.t = i18nExtensionsDirective

// Transpile is-https (IE11)
this.options.build.transpile = this.options.build.transpile || []
this.options.build.transpile.push('is-https')
}
30 changes: 1 addition & 29 deletions src/templates/utils-common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Cookie from 'cookie'
import JsCookie from 'js-cookie'
import isHTTPS from 'is-https'
import { hasProtocol } from 'ufo'

/** @typedef {import('../../types/internal').ResolvedOptions} ResolvedOptions */
Expand Down Expand Up @@ -137,35 +138,6 @@ 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: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7493,6 +7493,11 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
dependencies:
is-extglob "^2.1.1"

is-https@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/is-https/-/is-https-4.0.0.tgz#9ee725a334fb517b988278d2674efc96e4f348ed"
integrity sha512-FeMLiqf8E5g6SdiVJsPcNZX8k4h2fBs1wp5Bb6uaNxn58ufK1axBqQZdmAQsqh0t9BuwFObybrdVJh6MKyPlyg==

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