@plurid/plurid-react-server 0.0.0-16 → 0.0.0-17

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.
@@ -228,7 +228,7 @@ var template = async (data) => {
228
228
 
229
229
  ${headScripts.join("\n")}
230
230
 
231
- <script src="${vendorScriptSource}"></script>
231
+ ${vendorScriptSource ? `<script src="${vendorScriptSource}"></script>` : ""}
232
232
  <script defer src="${mainScriptSource}"></script>
233
233
  </head>
234
234
  <body ${bodyAttributes}>
@@ -308,7 +308,7 @@ var PluridRenderer = class {
308
308
  this.styles = styles;
309
309
  this.headScripts = headScripts;
310
310
  this.bodyScripts = bodyScripts;
311
- this.vendorScriptSource = vendorScriptSource || DEFAULT_RENDERER_VENDOR_SCRIPT_SOURCE;
311
+ this.vendorScriptSource = vendorScriptSource ?? DEFAULT_RENDERER_VENDOR_SCRIPT_SOURCE;
312
312
  this.mainScriptSource = mainScriptSource || DEFAULT_RENDERER_MAIN_SCRIPT_SOURCE;
313
313
  this.root = root || DEFAULT_RENDERER_ROOT;
314
314
  this.content = assetsPathRewrite(content) || "";
@@ -875,7 +875,7 @@ var PluridServer = class {
875
875
  error
876
876
  );
877
877
  }
878
- response.status(500).send(SERVER_ERROR_TEMPLATE);
878
+ response.status(500).send(this.template?.errorHtml || SERVER_ERROR_TEMPLATE);
879
879
  return;
880
880
  }
881
881
  }
@@ -983,7 +983,7 @@ var PluridServer = class {
983
983
  error
984
984
  );
985
985
  }
986
- response.status(500).send(SERVER_ERROR_TEMPLATE);
986
+ response.status(500).send(this.template?.errorHtml || SERVER_ERROR_TEMPLATE);
987
987
  return;
988
988
  }
989
989
  }
@@ -1155,7 +1155,7 @@ var PluridServer = class {
1155
1155
  const {
1156
1156
  helmet
1157
1157
  } = this.helmet;
1158
- const head = helmet ? `
1158
+ const helmetHead = helmet ? `
1159
1159
  ${helmet.meta.toString()}
1160
1160
  ${helmet.title.toString()}
1161
1161
  ${helmet.base.toString()}
@@ -1164,6 +1164,7 @@ var PluridServer = class {
1164
1164
  ${helmet.noscript.toString()}
1165
1165
  ${helmet.script.toString()}
1166
1166
  ` : "";
1167
+ const head = helmetHead + this.buildStaticHead();
1167
1168
  const htmlAttributes = {
1168
1169
  ...this.template?.htmlAttributes,
1169
1170
  ...helmet?.htmlAttributes.toComponent()
@@ -1202,6 +1203,67 @@ var PluridServer = class {
1202
1203
  });
1203
1204
  return renderer;
1204
1205
  }
1206
+ /**
1207
+ * Build the static `<head>` markup from the template config (favicon set,
1208
+ * manifest, default title / meta / links). Returns an empty string when none
1209
+ * are configured, so the head is byte-identical to before for existing apps.
1210
+ */
1211
+ buildStaticHead() {
1212
+ const template2 = this.template;
1213
+ if (!template2) {
1214
+ return "";
1215
+ }
1216
+ const escapeAttribute2 = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
1217
+ const escapeText = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1218
+ const parts = [];
1219
+ const favicon = template2.favicon;
1220
+ if (typeof favicon === "string") {
1221
+ parts.push(`<link rel="icon" href="${escapeAttribute2(favicon)}">`);
1222
+ } else if (favicon) {
1223
+ if (favicon.icon) {
1224
+ parts.push(`<link rel="icon" href="${escapeAttribute2(favicon.icon)}">`);
1225
+ }
1226
+ if (favicon.apple) {
1227
+ parts.push(`<link rel="apple-touch-icon" href="${escapeAttribute2(favicon.apple)}">`);
1228
+ }
1229
+ for (const [size, href] of Object.entries(favicon.sizes || {})) {
1230
+ parts.push(`<link rel="icon" sizes="${escapeAttribute2(size)}" href="${escapeAttribute2(href)}">`);
1231
+ }
1232
+ if (favicon.maskIcon) {
1233
+ const color = favicon.themeColor ? ` color="${escapeAttribute2(favicon.themeColor)}"` : "";
1234
+ parts.push(`<link rel="mask-icon" href="${escapeAttribute2(favicon.maskIcon)}"${color}>`);
1235
+ }
1236
+ if (favicon.themeColor) {
1237
+ parts.push(`<meta name="theme-color" content="${escapeAttribute2(favicon.themeColor)}">`);
1238
+ }
1239
+ }
1240
+ if (template2.manifest) {
1241
+ parts.push(`<link rel="manifest" href="${escapeAttribute2(template2.manifest)}">`);
1242
+ }
1243
+ const head = template2.head;
1244
+ if (head) {
1245
+ if (head.title) {
1246
+ parts.push(`<title>${escapeText(head.title)}</title>`);
1247
+ }
1248
+ if (head.description) {
1249
+ parts.push(`<meta name="description" content="${escapeAttribute2(head.description)}">`);
1250
+ }
1251
+ for (const meta of head.meta || []) {
1252
+ const selector = meta.name ? `name="${escapeAttribute2(meta.name)}"` : meta.property ? `property="${escapeAttribute2(meta.property)}"` : "";
1253
+ if (!selector) {
1254
+ continue;
1255
+ }
1256
+ parts.push(`<meta ${selector} content="${escapeAttribute2(meta.content)}">`);
1257
+ }
1258
+ for (const link of head.links || []) {
1259
+ parts.push(`<link rel="${escapeAttribute2(link.rel)}" href="${escapeAttribute2(link.href)}">`);
1260
+ }
1261
+ }
1262
+ if (parts.length === 0) {
1263
+ return "";
1264
+ }
1265
+ return "\n " + parts.join("\n ");
1266
+ }
1205
1267
  async getContentAndStyles(isoMatch, pluridMetastate, preserveResult, matchedPlane) {
1206
1268
  const stylesheet = new ServerStyleSheet();
1207
1269
  let content = "";
@@ -1275,6 +1337,7 @@ var PluridServer = class {
1275
1337
  open: partialOptions?.open ?? DEFAULT_SERVER_OPTIONS.OPEN,
1276
1338
  buildDirectory: partialOptions?.buildDirectory || DEFAULT_SERVER_OPTIONS.BUILD_DIRECTORY,
1277
1339
  assetsDirectory: partialOptions?.assetsDirectory || DEFAULT_SERVER_OPTIONS.ASSETS_DIRECTORY,
1340
+ publicDirectory: partialOptions?.publicDirectory || "",
1278
1341
  gatewayEndpoint: partialOptions?.gatewayEndpoint || DEFAULT_SERVER_OPTIONS.GATEWAY,
1279
1342
  staticCache: partialOptions?.staticCache || 0,
1280
1343
  ignore: partialOptions?.ignore || [],
@@ -1327,6 +1390,15 @@ var PluridServer = class {
1327
1390
  maxAge: this.options.staticCache
1328
1391
  })
1329
1392
  );
1393
+ const publicPath = this.options.publicDirectory || path2.join(this.options.buildDirectory, "public");
1394
+ if (fs2.existsSync(publicPath)) {
1395
+ this.serverApplication.use(
1396
+ express.static(publicPath, {
1397
+ index: false,
1398
+ maxAge: this.options.staticCache
1399
+ })
1400
+ );
1401
+ }
1330
1402
  this.loadMiddleware();
1331
1403
  }
1332
1404
  loadMiddleware() {