fix: render live V2X vehicles in Cesium preview
This commit is contained in:
@@ -30,6 +30,10 @@ async function request(port, pathName, options = {}) {
|
||||
assert.equal(isProxyPath("/package/manifest.json"), false);
|
||||
assert.equal(upstreamPath("/api/facilities/api/sys/login?x=1"), "/facilities/api/sys/login?x=1");
|
||||
assert.equal(upstreamPath("/websocket/network/ws/network/signal"), "/network/ws/network/signal");
|
||||
// An upstream base path (deployments front the API as /dashboardApi) is kept.
|
||||
assert.equal(upstreamPath("/api/facilities/api/sys/login", "/dashboardApi"), "/dashboardApi/facilities/api/sys/login");
|
||||
assert.equal(upstreamPath("/websocket/network/ws/x", "/dashboardWebsocket/"), "/dashboardWebsocket/network/ws/x");
|
||||
assert.equal(upstreamPath("/api/x", "/"), "/x");
|
||||
|
||||
const upstream = http.createServer((req, res) => {
|
||||
let body = "";
|
||||
@@ -59,6 +63,28 @@ async function request(port, pathName, options = {}) {
|
||||
} finally {
|
||||
await Promise.all([new Promise((resolve) => preview.close(resolve)), new Promise((resolve) => upstream.close(resolve))]);
|
||||
}
|
||||
|
||||
// Same upstream, but reached through a prefixed base path.
|
||||
const prefixedUpstream = http.createServer((req, res) => {
|
||||
res.setHeader("Content-Type", "application/json");
|
||||
res.end(JSON.stringify({ path: req.url }));
|
||||
});
|
||||
const prefixedPort = await listen(prefixedUpstream);
|
||||
const prefixedPreview = createV2xPreviewServer({
|
||||
root: path.join(__dirname, "..", "outputs", "fengshu-er-road"),
|
||||
upstream: `http://127.0.0.1:${prefixedPort}/dashboardApi`,
|
||||
wsUpstream: `http://127.0.0.1:${prefixedPort}/dashboardWebsocket`,
|
||||
});
|
||||
const prefixedPreviewPort = await listen(prefixedPreview);
|
||||
try {
|
||||
const proxied = await request(prefixedPreviewPort, "/api/facilities/api/sys/login");
|
||||
assert.deepEqual(JSON.parse(proxied.body), { path: "/dashboardApi/facilities/api/sys/login" });
|
||||
} finally {
|
||||
await Promise.all([
|
||||
new Promise((resolve) => prefixedPreview.close(resolve)),
|
||||
new Promise((resolve) => prefixedUpstream.close(resolve)),
|
||||
]);
|
||||
}
|
||||
console.log("V2X preview server tests passed.");
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user