MCPcopy
hub / github.com/CesiumGS/cesium / createRoute

Function createRoute

scripts/createRoute.js:55–94  ·  view source on GitHub ↗

* @param {Express} app * @param {string} name * @param {string} route * @param {*} context * @param {ContextCache[]} dependantCaches * @returns

(app, name, route, context, dependantCaches)

Source from the content-addressed store, hash-verified

53 * @returns
54 */
55function createRoute(app, name, route, context, dependantCaches) {
56 const cache = new ContextCache(context);
57 app.get(route, async function (req, res, next) {
58 const fileName = path.basename(req.originalUrl);
59
60 // Multiple files may be requested at this path, calling this function in quick succession.
61 // Await the previous build before re-building again.
62 try {
63 await cache.promise;
64 } catch {
65 // Error is reported upstream
66 }
67
68 if (!cache.isBuilt()) {
69 try {
70 const start = performance.now();
71 if (dependantCaches) {
72 await Promise.all(
73 dependantCaches.map((dependantCache) => {
74 if (!dependantCache.isBuilt()) {
75 return dependantCache.rebuild();
76 }
77 }),
78 );
79 }
80 await cache.rebuild();
81 console.log(
82 `Built ${name} in ${formatTimeSinceInSeconds(start)} seconds.`,
83 );
84 } catch (e) {
85 next(e);
86 }
87 }
88
89 const result = /** @type {BuildResult} */ (cache.result);
90 return serveResult(result, fileName, res, next);
91 });
92
93 return cache;
94}
95
96export default createRoute;

Callers 1

server.jsFile · 0.85

Calls 8

isBuiltMethod · 0.95
rebuildMethod · 0.95
serveResultFunction · 0.85
nowMethod · 0.80
mapMethod · 0.80
formatTimeSinceInSecondsFunction · 0.70
nextFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…