cloud-url-resolver
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,19 @@ const inBrowser = typeof window !== "undefined"; | ||
}); | ||
const protocolRegex = /^https?:\/\//; | ||
const workspaceDefinedError = Error("workspace url not defined"); | ||
function transformWithEndingPort(port, resolvedProtocol, origin, regex, replacer) { | ||
const url = origin.replace(regex, "").replace(protocolRegex, ""); | ||
if (!url) { | ||
throw workspaceDefinedError; | ||
} | ||
return `${resolvedProtocol}://${url}${port}.${replacer}`; | ||
} | ||
function transformWithStartingPort(port, resolvedProtocol, origin) { | ||
const regex = /^https?:\/\/\d{1,5}/; | ||
const url = origin.replace(regex, ""); | ||
if (!url) { | ||
throw workspaceDefinedError; | ||
} | ||
return `${resolvedProtocol}://${port}${url}`; | ||
} | ||
/** | ||
@@ -17,18 +34,9 @@ * Cloud URL transformation function. Designed to run on either SSR or browser. | ||
if (origin.endsWith("gitpod.io")) { | ||
const regex = /^https?:\/\/\d{1,5}/; | ||
const url = origin.replace(regex, ""); | ||
if (!url) { | ||
throw Error("workspace url not defined"); | ||
} | ||
return `${resolvedProtocol}://${port}${url}`; | ||
return transformWithStartingPort(port, resolvedProtocol, origin); | ||
} else if (origin.endsWith("app.github.dev")) { | ||
const protocolRegex = /^https?:\/\//; | ||
const regex = /\d{1,5}\.app\.github\.dev$/; | ||
const url = origin.replace(regex, "").replace(protocolRegex, ""); | ||
if (!url) { | ||
throw Error("workspace url not defined"); | ||
} | ||
return `${resolvedProtocol}://${url}${port}.app.github.dev`; | ||
return transformWithEndingPort(port, resolvedProtocol, origin, /\d{1,5}\.app\.github\.dev$/, "app.github.dev"); | ||
} else if (origin.endsWith("glitch.me")) { | ||
return `${resolvedProtocol}://${new URL(origin).host}`; | ||
} else if (origin.endsWith("csb.app")) { | ||
return transformWithEndingPort(port, resolvedProtocol, origin, /\d{1,5}\.csb\.app$/, "csb.app"); | ||
} | ||
@@ -35,0 +43,0 @@ } |
{ | ||
"name": "cloud-url-resolver", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Allow changing the port and protocol of any common development url", | ||
@@ -5,0 +5,0 @@ "repository": { |
# cloud-url-resolver | ||
![NPM Version](https://img.shields.io/npm/v/cloud-url-resolver) | ||
[![NPM Version](https://img.shields.io/npm/v/cloud-url-resolver)](https://npmjs.com/package/cloud-url-resolver) | ||
@@ -12,2 +12,3 @@ easily resolve protocol/port setups on any development platform | ||
- [Glitch](https://glitch.com/) - _no port support_ | ||
- [CodeSandbox](https://codesandbox.io) | ||
@@ -14,0 +15,0 @@ If you would like to add support for another platform, please open an issue about it. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7025
58
23