Skip to content

Commit

Permalink
Handle added files on dev server, don't crash server on error
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed Oct 9, 2024
1 parent 750c9ef commit 30f592e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
10 changes: 8 additions & 2 deletions scripts/createRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ function serveResult (result, fileName, res, next) {
function createRoute(app, name, route, context, dependantCaches) {
const cache = new ContextCache(context);
app.get(route, async function (req, res, next) {
const fileName = path.basename(req.originalUrl);

// Multiple files may be requested at this path, calling this function in quick succession.
// Await the previous build before re-building again.
await cache.promise;
try {
await cache.promise;
} catch {
// Error is reported upstream
}

if (!cache.isBuilt()) {
try {
Expand All @@ -57,7 +63,7 @@ function createRoute(app, name, route, context, dependantCaches) {
}
}

return serveResult(cache.result, path.basename(req.originalUrl), res, next);
return serveResult(cache.result, fileName, res, next);
});

return cache;
Expand Down
30 changes: 20 additions & 10 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import yargs from "yargs";
import ContextCache from "./scripts/ContextCache.js";
import createRoute from "./scripts/createRoute.js";

import {
createCesiumJs,
createJsHintOptions,
createCombinedSpecList,
glslToJavaScript,
createIndexJs,
buildCesium,
} from "./scripts/build.js";

const argv = yargs(process.argv)
.options({
port: {
Expand All @@ -37,15 +46,6 @@ const argv = yargs(process.argv)
})
.help().argv;

import {
createCesiumJs,
createJsHintOptions,
createCombinedSpecList,
glslToJavaScript,
createIndexJs,
buildCesium,
} from "./scripts/build.js";

const outputDirectory = path.join("Build", "CesiumDev");

function formatTimeSinceInSeconds(start) {
Expand Down Expand Up @@ -214,12 +214,22 @@ async function generateDevelopmentBuild() {
ignoreInitial: true,
},
);
sourceCodeWatcher.on("all", async () => {

// eslint-disable-next-line no-unused-vars
sourceCodeWatcher.on("all", async (action, path) => {
esmCache.clear();
iifeCache.clear();
workersCache.clear();
iifeWorkersCache.clear();
jsHintOptionsCache = undefined;

// Get the workspace token from the path, and rebuild that workspace's index.js
const workspaceRegex = /packages\/(.+?)\/.+\.js/;
const result = path.match(workspaceRegex);
if (result) {
await createIndexJs(result[1]);
}

await createCesiumJs();
});

Expand Down

0 comments on commit 30f592e

Please sign in to comment.