MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / deriveHttpOrigin

Function deriveHttpOrigin

packages/vite/hmr/client/utils.ts:144–163  ·  view source on GitHub ↗
(wsUrl: string | undefined)

Source from the content-addressed store, hash-verified

142export const moduleFetchCache = new Map<string, string>(); // spec -> resolved HTTP URL
143
144export function deriveHttpOrigin(wsUrl: string | undefined) {
145 try {
146 // Prefer explicit HTTP origin provided by entry-runtime when available
147 try {
148 const g: any = globalThis as any;
149 if (g && typeof g.__NS_HTTP_ORIGIN__ === 'string' && /^https?:\/\//.test(g.__NS_HTTP_ORIGIN__)) {
150 return String(g.__NS_HTTP_ORIGIN__);
151 }
152 } catch {}
153 const url = new URL(wsUrl || 'ws://localhost:5173/ns-hmr');
154 const http = url.protocol === 'wss:' ? 'https:' : 'http:';
155 const origin = `${http}//${url.host}`;
156 if (!/^https?:\/\/[\w\-.:\[\]]+$/.test(origin)) {
157 console.warn('[hmr-client][origin] invariant failed for', wsUrl, '→', origin);
158 }
159 return origin;
160 } catch {
161 return 'http://localhost:5173';
162 }
163}
164
165export async function requestModuleFromServer(spec: string): Promise<string> {
166 const isSfcArtifact = (s: string) => /(?:^|\/)sfc-[a-f0-9]{8}\.mjs$/i.test(s) || /\/_ns_hmr\/src\/sfc\//.test(s) || /__NSDOC__\/_ns_hmr\/src\/sfc\//.test(s);

Callers 10

tryNextFunction · 0.85
handleHmrMessageFunction · 0.85
requestModuleFromServerFunction · 0.85
safeDynImportFunction · 0.85
dumpDynImportDiagnosticsFunction · 0.85
normalizeSpecFunction · 0.85
resolveSfcVariantSpecFunction · 0.85
resolveSfcAssemblerSpecFunction · 0.85
resolveSfcMetaSpecFunction · 0.85
requestModuleFromServerFunction · 0.85

Calls 3

warnMethod · 0.80
StringClass · 0.50
testMethod · 0.45

Tested by

no test coverage detected