brazy-auth
Version:
Authentication for Next.js
24 lines (23 loc) • 621 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = parseUrl;
function parseUrl(url) {
var _url2;
const defaultUrl = new URL("https://dev.example.com/api/auth");
if (url && !url.startsWith("http")) {
url = `https://${url}`;
}
const _url = new URL((_url2 = url) !== null && _url2 !== void 0 ? _url2 : defaultUrl);
const path = (_url.pathname === "/" ? defaultUrl.pathname : _url.pathname
).replace(/\/$/, "");
const base = `${_url.origin}${path}`;
return {
origin: _url.origin,
host: _url.host,
path,
base,
toString: () => base
};
}