Skip to content

refactor: remove is-absolute-url in favor of method #3609

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

Merged
merged 1 commit into from
Aug 12, 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
19 changes: 14 additions & 5 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ class Server {
};
}

// eslint-disable-next-line class-methods-use-this
static isAbsoluteURL(URL) {
// Don't match Windows paths `c:\`
if (/^[a-zA-Z]:\\/.test(URL)) {
return false;
}

// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(URL);
}

static async getHostname(hostname) {
if (hostname === "local-ip") {
return (await internalIp.v4()) || (await internalIp.v6()) || "0.0.0.0";
Expand Down Expand Up @@ -523,10 +535,8 @@ class Server {
}

if (options.static) {
const isAbsoluteUrl = require("is-absolute-url");

options.static.forEach((staticOption) => {
if (isAbsoluteUrl(staticOption.directory)) {
if (Server.isAbsoluteURL(staticOption.directory)) {
throw new Error("Using a URL as static.directory is not supported");
}

Expand Down Expand Up @@ -1193,7 +1203,6 @@ class Server {
}

openBrowser(defaultOpenTarget) {
const isAbsoluteUrl = require("is-absolute-url");
const open = require("open");

Promise.all(
Expand All @@ -1203,7 +1212,7 @@ class Server {
if (item.target === "<url>") {
openTarget = defaultOpenTarget;
} else {
openTarget = isAbsoluteUrl(item.target)
openTarget = Server.isAbsoluteURL(item.target)
? item.target
: new URL(item.target, defaultOpenTarget).toString();
}
Expand Down
17 changes: 0 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"http-proxy-middleware": "^2.0.0",
"internal-ip": "^6.2.0",
"ipaddr.js": "^2.0.1",
"is-absolute-url": "^3.0.3",
"killable": "^1.0.1",
"open": "^8.0.9",
"p-retry": "^4.5.0",
Expand Down