Jhernandez has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/371509 )
Change subject: Server: Don't crash when unable to load the asset-manifest.json
......................................................................
Server: Don't crash when unable to load the asset-manifest.json
Some times in development when starting the processes the server starts
and the asset-manifest.json in dist/public still hasn't been generated.
Don't crash when not found, just initialize with no assets.
Change-Id: I6b954e6403787387c982b02c944171feeb28d72d
---
M src/server/index.ts
M src/server/templates/page.ts
2 files changed, 10 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/marvin refs/changes/09/371509/1
diff --git a/src/server/index.ts b/src/server/index.ts
index 76673c0..1be1942 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -2,7 +2,12 @@
import page, { AssetsManifest } from "./templates/page";
import app from "../common/components/app";
-const assets: AssetsManifest =
require("../../dist/public/assets-manifest.json");
+let assets: AssetsManifest = {};
+try {
+ assets = require("../../dist/public/assets-manifest.json");
+} catch (e) {
+ console.error("Unable to load the static assets manifest file");
+}
const { PORT = 3000 } = process.env;
const server = express();
diff --git a/src/server/templates/page.ts b/src/server/templates/page.ts
index 4929a35..9465595 100644
--- a/src/server/templates/page.ts
+++ b/src/server/templates/page.ts
@@ -14,6 +14,9 @@
}
export default function page({ title, body = "", assets }: PageParams): string
{
+ const scripts = [];
+ assets.index && assets.index.js && scripts.push(assets.index.js);
+
return `
<!DOCTYPE html>
<html lang="en">
@@ -25,7 +28,7 @@
</head>
<body>
<div id="root">${body}</div>
- <script type="text/javascript" src="./${assets.index.js}"></script>
+ ${scripts.map(s => `<script type="text/javascript"
src="./${s}"></script>`)}
</body>
</html>`;
}
--
To view, visit https://gerrit.wikimedia.org/r/371509
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b954e6403787387c982b02c944171feeb28d72d
Gerrit-PatchSet: 1
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits