Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

current-url

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

current-url - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

3

dist/browser/browser.js

@@ -8,2 +8,5 @@ "use strict";

/**
* Get the current URL from the `window.location`.
*/
var currentUrl = function currentUrl() {

@@ -10,0 +13,0 @@ return new URL(window.location.href);

48

dist/browser/server.js

@@ -12,3 +12,3 @@ "use strict";

var _url = require("url");
var _getRequestOrigin = require("get-request-origin");

@@ -20,31 +20,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

};
/**
* Get the current URL from a Node request object.
*/
var parseHostHeader = function parseHostHeader(req) {
var host = req.headers.host;
if (typeof host !== 'string') {
return {};
}
var _parseUrl = (0, _url.parse)(req.originalUrl || req.url || ''),
urlProtocol = _parseUrl.protocol;
var secure = req.secure || req.connection && req.connection.encrypted;
var protocolPattern = /^(?:[a-z]+:)?\/\//i;
var hostProtocol = protocolPattern.test(host) ? host.match(protocolPattern)[0] : null;
var fallbackProtocol = secure ? 'https:' : 'http:';
var protocol = urlProtocol || hostProtocol || fallbackProtocol;
return (0, _url.parse)(hostProtocol ? host : "".concat(protocol, "//").concat(host));
};
var getProxiedUrl = function getProxiedUrl(req) {
var url = new URL((0, _originalUrl["default"])(req).full);
if (req.headers['x-replaced-path']) {
url.pathname = req.headers['x-replaced-path'];
}
return url;
};
var currentUrl = function currentUrl(req) {

@@ -61,15 +37,15 @@ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

if (!opts.ignoreProxies) {
return getProxiedUrl(req);
if (opts.ignoreProxies) {
return new URL(req.originalUrl || req.url, (0, _getRequestOrigin.getRequestOrigin)(req));
}
var _parseHostHeader = parseHostHeader(req),
protocol = _parseHostHeader.protocol,
hostname = _parseHostHeader.hostname,
port = _parseHostHeader.port;
var url = new URL((0, _originalUrl["default"])(req).full);
var baseUrl = "".concat(protocol, "//").concat(hostname).concat(port ? ":".concat(port) : '');
return new URL(req.originalUrl || req.url, baseUrl);
if (req.headers['x-replaced-path']) {
url.pathname = req.headers['x-replaced-path'];
}
return url;
};
exports.currentUrl = currentUrl;

@@ -8,4 +8,7 @@ "use strict";

/**
* Get the current URL from the `window.location`.
*/
const currentUrl = () => new URL(window.location.href);
exports.currentUrl = currentUrl;

@@ -12,3 +12,3 @@ "use strict";

var _url = require("url");
var _getRequestOrigin = require("get-request-origin");

@@ -18,33 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const isIncomingMessage = req => req.name === 'IncomingMessage' || req.constructor.name === 'IncomingMessage' || req instanceof _http.IncomingMessage;
/**
* Get the current URL from a Node request object.
*/
const parseHostHeader = req => {
const {
host
} = req.headers;
if (typeof host !== 'string') {
return {};
}
const {
protocol: urlProtocol
} = (0, _url.parse)(req.originalUrl || req.url || '');
const secure = req.secure || req.connection && req.connection.encrypted;
const protocolPattern = /^(?:[a-z]+:)?\/\//i;
const hostProtocol = protocolPattern.test(host) ? host.match(protocolPattern)[0] : null;
const fallbackProtocol = secure ? 'https:' : 'http:';
const protocol = urlProtocol || hostProtocol || fallbackProtocol;
return (0, _url.parse)(hostProtocol ? host : `${protocol}//${host}`);
};
const getProxiedUrl = req => {
const url = new URL((0, _originalUrl.default)(req).full);
if (req.headers['x-replaced-path']) {
url.pathname = req.headers['x-replaced-path'];
}
return url;
};
const currentUrl = (req, opts = {}) => {

@@ -59,15 +33,15 @@ if (!req) {

if (!opts.ignoreProxies) {
return getProxiedUrl(req);
if (opts.ignoreProxies) {
return new URL(req.originalUrl || req.url, (0, _getRequestOrigin.getRequestOrigin)(req));
}
const {
protocol,
hostname,
port
} = parseHostHeader(req);
const baseUrl = `${protocol}//${hostname}${port ? `:${port}` : ''}`;
return new URL(req.originalUrl || req.url, baseUrl);
const url = new URL((0, _originalUrl.default)(req).full);
if (req.headers['x-replaced-path']) {
url.pathname = req.headers['x-replaced-path'];
}
return url;
};
exports.currentUrl = currentUrl;
{
"name": "current-url",
"version": "2.1.0",
"version": "2.1.1",
"description": "Get the current URL isomorphically.",

@@ -36,2 +36,3 @@ "author": "Alex Mendes",

"dependencies": {
"get-request-origin": "^1.0.0",
"original-url": "^1.2.3"

@@ -38,0 +39,0 @@ },

@@ -0,1 +1,4 @@

/**
* Get the current URL from the `window.location`.
*/
export const currentUrl = () => new URL(window.location.href);
import { IncomingMessage } from 'http';
import originalUrl from 'original-url';
import { parse as parseUrl } from 'url';
import { getRequestOrigin } from 'get-request-origin';

@@ -11,29 +11,5 @@ const isIncomingMessage = (req) => (

const parseHostHeader = (req) => {
const { host } = req.headers;
if (typeof host !== 'string') {
return {};
}
const { protocol: urlProtocol } = parseUrl(req.originalUrl || req.url || '');
const secure = req.secure || (req.connection && req.connection.encrypted);
const protocolPattern = /^(?:[a-z]+:)?\/\//i;
const hostProtocol = protocolPattern.test(host) ? host.match(protocolPattern)[0] : null;
const fallbackProtocol = secure ? 'https:' : 'http:';
const protocol = urlProtocol || hostProtocol || fallbackProtocol;
return parseUrl(hostProtocol ? host : `${protocol}//${host}`);
};
const getProxiedUrl = (req) => {
const url = new URL(originalUrl(req).full);
if (req.headers['x-replaced-path']) {
url.pathname = req.headers['x-replaced-path'];
}
return url;
};
/**
* Get the current URL from a Node request object.
*/
export const currentUrl = (req, opts = {}) => {

@@ -48,10 +24,13 @@ if (!req) {

if (!opts.ignoreProxies) {
return getProxiedUrl(req);
if (opts.ignoreProxies) {
return new URL(req.originalUrl || req.url, getRequestOrigin(req));
}
const { protocol, hostname, port } = parseHostHeader(req);
const baseUrl = `${protocol}//${hostname}${port ? `:${port}` : ''}`;
const url = new URL(originalUrl(req).full);
return new URL(req.originalUrl || req.url, baseUrl);
if (req.headers['x-replaced-path']) {
url.pathname = req.headers['x-replaced-path'];
}
return url;
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc