get-request-origin
Advanced tools
Comparing version 1.0.1 to 1.1.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getRequestOrigin = void 0; | ||
var _url = require("url"); | ||
const parseOrigin = url => { | ||
const { | ||
protocol, | ||
hostname, | ||
port | ||
} = (0, _url.parse)(url); | ||
return `${protocol}//${hostname}${port ? `:${port}` : ''}`; | ||
const url_1 = require("url"); | ||
const parseOrigin = (url) => { | ||
const { protocol, hostname, port } = (0, url_1.parse)(url); | ||
return `${protocol}//${hostname}${port ? `:${port}` : ''}`; | ||
}; | ||
@@ -21,23 +12,14 @@ /** | ||
*/ | ||
const getRequestOrigin = req => { | ||
const url = req.originalUrl || req.url; | ||
const { | ||
host | ||
} = req.headers || {}; | ||
if (typeof host !== 'string') { | ||
return parseOrigin(url); | ||
} | ||
const { | ||
protocol: urlProtocol | ||
} = (0, _url.parse)(url); | ||
const isSecure = req.secure || (req.connection || {}).encrypted; | ||
const fallbackProtocol = isSecure ? 'https:' : 'http:'; | ||
const protocol = urlProtocol || fallbackProtocol; | ||
return parseOrigin(`${protocol}//${host}`); | ||
const getRequestOrigin = (req) => { | ||
const url = req.originalUrl || req.url; | ||
const { host } = req.headers || {}; | ||
if (typeof host !== 'string' && url) { | ||
return parseOrigin(url); | ||
} | ||
const urlProtocol = url ? (0, url_1.parse)(url).protocol : null; | ||
const isSecure = req.secure || (req.connection || {}).encrypted; | ||
const fallbackProtocol = isSecure ? 'https:' : 'http:'; | ||
const protocol = urlProtocol || fallbackProtocol; | ||
return parseOrigin(`${protocol}//${host}`); | ||
}; | ||
exports.getRequestOrigin = getRequestOrigin; | ||
exports.getRequestOrigin = getRequestOrigin; |
{ | ||
"name": "get-request-origin", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Get the URL origin from a Node request object.", | ||
@@ -8,4 +8,5 @@ "author": "Alex Mendes", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "babel src -d dist", | ||
"build": "tsc", | ||
"test": "jest", | ||
@@ -38,2 +39,3 @@ "prebuild": "rimraf dist", | ||
"@babel/preset-env": "^7.9.6", | ||
"@babel/preset-typescript": "^7.21.5", | ||
"@commitlint/config-conventional": "^16.0.0", | ||
@@ -46,2 +48,3 @@ "@semantic-release/changelog": "^6.0.1", | ||
"@semantic-release/release-notes-generator": "^10.0.3", | ||
"@typescript-eslint/parser": "^5.59.1", | ||
"babel-jest": "^25.5.1", | ||
@@ -51,2 +54,3 @@ "commitlint": "^8.3.5", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-import-resolver-typescript": "^3.5.5", | ||
"eslint-plugin-import": "^2.25.4", | ||
@@ -57,4 +61,6 @@ "eslint-plugin-jest": "^26.0.0", | ||
"rimraf": "^3.0.2", | ||
"semantic-release": "^19.0.2" | ||
"semantic-release": "^19.0.2", | ||
"ts-jest": "^29.1.0", | ||
"typescript": "^5.0.4" | ||
} | ||
} |
4685
6
66
26