UNPKG

@maskedeng-tom/ssrsx

Version:
57 lines 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useLocation = void 0; const url_1 = require("url"); const jsx_parser_1 = require("ssrsxjsx/jsx-parser"); const support_1 = require("../../server/support"); const joinPath_1 = require("../lib/joinPath"); //////////////////////////////////////////////////////////////////////////////// const useLocation = () => { var _a; // const ssrsx = (0, jsx_parser_1.getCurrentSsrsx)(); const baseUrl = (_a = ssrsx === null || ssrsx === void 0 ? void 0 : ssrsx.baseUrl) !== null && _a !== void 0 ? _a : ''; // const server = (0, support_1.getServer)(); const url = (0, support_1.getUrl)(server).replace(RegExp(`^${baseUrl}`), ''); const protocol = (0, support_1.getProtocol)(server); const hostname = (0, support_1.getHostname)(server); const port = (0, support_1.getPort)(server); // const fullUrl = `${protocol}://${hostname}:${port}${url}`; const parsedUrl = new url_1.URL(fullUrl); // const search = {}; for (const [key, value] of parsedUrl.searchParams.entries()) { if (search[key]) { if (Array.isArray(search[key])) { search[key].push(value); } else { search[key] = [search[key], value]; } } else { search[key] = value; } } // return { protocol: parsedUrl.protocol, host: parsedUrl.host, hostname: parsedUrl.hostname, port: Number(parsedUrl.port), href: `${protocol}://${hostname}:${port}${(0, support_1.getUrl)(server)}`, pathname: parsedUrl.pathname, search: search, hash: parsedUrl.hash, // realPathname: (0, joinPath_1.joinPath)(baseUrl, parsedUrl.pathname), realPath: (p) => { return (0, joinPath_1.joinPath)(baseUrl, p); } }; // }; exports.useLocation = useLocation; //# sourceMappingURL=useLocation.js.map