@expo/serve-sim 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/middleware.js +72 -72
- package/dist/serve-sim.js +102 -102
- package/package.json +1 -1
- package/src/middleware.ts +27 -4
package/package.json
CHANGED
package/src/middleware.ts
CHANGED
|
@@ -977,6 +977,8 @@ export function previewConfigForState(
|
|
|
977
977
|
execToken: string,
|
|
978
978
|
streamSettingsOrCodec?: StreamSettings | string,
|
|
979
979
|
proxyHelpers = false,
|
|
980
|
+
requirePreviewToken = false,
|
|
981
|
+
shareUrl?: string,
|
|
980
982
|
): ServeSimState & {
|
|
981
983
|
basePath: string;
|
|
982
984
|
logsEndpoint: string;
|
|
@@ -1003,6 +1005,8 @@ export function previewConfigForState(
|
|
|
1003
1005
|
codec?: string;
|
|
1004
1006
|
streamSettings?: StreamSettings;
|
|
1005
1007
|
proxyHelpers?: boolean;
|
|
1008
|
+
requireToken?: boolean;
|
|
1009
|
+
shareUrl?: string;
|
|
1006
1010
|
} {
|
|
1007
1011
|
const gridApiBase = (base === "" ? "" : base) + "/grid/api";
|
|
1008
1012
|
const legacyCodec = typeof streamSettingsOrCodec === "string" ? streamSettingsOrCodec : undefined;
|
|
@@ -1037,6 +1041,8 @@ export function previewConfigForState(
|
|
|
1037
1041
|
...(legacyCodec ? { codec: legacyCodec } : {}),
|
|
1038
1042
|
...(streamSettings ? { streamSettings } : {}),
|
|
1039
1043
|
...(proxyHelpers ? { proxyHelpers: true } : {}),
|
|
1044
|
+
...(requirePreviewToken ? { requireToken: true } : {}),
|
|
1045
|
+
...(shareUrl ? { shareUrl } : {}),
|
|
1040
1046
|
};
|
|
1041
1047
|
}
|
|
1042
1048
|
|
|
@@ -1502,6 +1508,8 @@ export interface SimMiddlewareOptions {
|
|
|
1502
1508
|
*/
|
|
1503
1509
|
metricsCorsOrigins?: string[];
|
|
1504
1510
|
frameAncestors?: string[];
|
|
1511
|
+
/** Public page the Share button copies instead of this preview's address. */
|
|
1512
|
+
shareUrl?: string;
|
|
1505
1513
|
/** @deprecated Use `streamSettings: { transport: "http", codec }`. */
|
|
1506
1514
|
codec?: string;
|
|
1507
1515
|
/**
|
|
@@ -1588,6 +1596,7 @@ export function simMiddleware(options?: SimMiddlewareOptions): SimMiddleware {
|
|
|
1588
1596
|
const requirePreviewToken = options?.requirePreviewToken ?? false;
|
|
1589
1597
|
const metricsCorsOrigins = options?.metricsCorsOrigins ?? [];
|
|
1590
1598
|
const frameAncestors = options?.frameAncestors ?? [];
|
|
1599
|
+
const shareUrl = options?.shareUrl;
|
|
1591
1600
|
|
|
1592
1601
|
// Simulator-settings requests run in-process (just the underlying simctl /
|
|
1593
1602
|
// ax-tool spawn) instead of round-tripping a full `node <cli>` exec per
|
|
@@ -1706,7 +1715,11 @@ export function simMiddleware(options?: SimMiddlewareOptions): SimMiddleware {
|
|
|
1706
1715
|
// Empty-state UI still polls /exec (boot/list helpers), so the page
|
|
1707
1716
|
// needs the bearer token even before a helper attaches. Inject a
|
|
1708
1717
|
// minimal config with just the basePath + token.
|
|
1709
|
-
const minimal = JSON.stringify({
|
|
1718
|
+
const minimal = JSON.stringify({
|
|
1719
|
+
basePath: base,
|
|
1720
|
+
execToken,
|
|
1721
|
+
...(shareUrl ? { shareUrl } : {}),
|
|
1722
|
+
});
|
|
1710
1723
|
html = html.replace(
|
|
1711
1724
|
"<!--__SIM_PREVIEW_CONFIG__-->",
|
|
1712
1725
|
`<script>window.__SIM_PREVIEW__=${minimal}</script>`,
|
|
@@ -1715,7 +1728,9 @@ export function simMiddleware(options?: SimMiddlewareOptions): SimMiddleware {
|
|
|
1715
1728
|
|
|
1716
1729
|
if (state) {
|
|
1717
1730
|
const remoteState = rewriteStateForRequestHost(state, hostForRequest(req), base, httpProtocolForRequest(req), proxyHelpers);
|
|
1718
|
-
const config = JSON.stringify(
|
|
1731
|
+
const config = JSON.stringify(
|
|
1732
|
+
previewConfigForState(remoteState, base, execToken, streamSettings, proxyHelpers, requirePreviewToken, shareUrl),
|
|
1733
|
+
);
|
|
1719
1734
|
const configScript = `<script>window.__SIM_PREVIEW__=${config}</script>`;
|
|
1720
1735
|
html = html.replace("<!--__SIM_PREVIEW_CONFIG__-->", configScript);
|
|
1721
1736
|
}
|
|
@@ -2153,7 +2168,13 @@ export function simMiddleware(options?: SimMiddlewareOptions): SimMiddleware {
|
|
|
2153
2168
|
"Cache-Control": "no-store",
|
|
2154
2169
|
});
|
|
2155
2170
|
const remoteState = state ? rewriteStateForRequestHost(state, hostForRequest(req), base, httpProtocolForRequest(req), proxyHelpers) : null;
|
|
2156
|
-
res.end(
|
|
2171
|
+
res.end(
|
|
2172
|
+
JSON.stringify(
|
|
2173
|
+
remoteState
|
|
2174
|
+
? previewConfigForState(remoteState, base, execToken, streamSettings, proxyHelpers, requirePreviewToken, shareUrl)
|
|
2175
|
+
: null,
|
|
2176
|
+
),
|
|
2177
|
+
);
|
|
2157
2178
|
return;
|
|
2158
2179
|
}
|
|
2159
2180
|
|
|
@@ -2289,7 +2310,9 @@ export function simMiddleware(options?: SimMiddlewareOptions): SimMiddleware {
|
|
|
2289
2310
|
const state = selectServeSimState(states, selectedDevice);
|
|
2290
2311
|
const remoteState = state ? rewriteStateForRequestHost(state, hostForRequest(req), base, httpProtocolForRequest(req), proxyHelpers) : null;
|
|
2291
2312
|
return JSON.stringify(
|
|
2292
|
-
remoteState
|
|
2313
|
+
remoteState
|
|
2314
|
+
? previewConfigForState(remoteState, base, execToken, streamSettings, proxyHelpers, requirePreviewToken, shareUrl)
|
|
2315
|
+
: null,
|
|
2293
2316
|
);
|
|
2294
2317
|
};
|
|
2295
2318
|
|