opencroc 1.8.4 → 1.8.5

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.
package/dist/cli/index.js CHANGED
@@ -8566,11 +8566,23 @@ async function startServer(opts) {
8566
8566
  const app = Fastify({ logger: false });
8567
8567
  await app.register(fastifyWebsocket);
8568
8568
  const webDir = resolve11(__dirname2, "../web");
8569
+ const builtIndexPath = join17(webDir, "dist", "index.html");
8570
+ function hasBuiltStudio() {
8571
+ return existsSync20(builtIndexPath);
8572
+ }
8573
+ function sendSpaEntry(reply) {
8574
+ if (hasBuiltStudio()) {
8575
+ return reply.sendFile("dist/index.html");
8576
+ }
8577
+ return reply.code(200).header("content-type", "text/html").send(getEmbeddedHtml());
8578
+ }
8579
+ function isAssetRequest(url) {
8580
+ return /\.[a-z0-9]+$/i.test(url) || url.startsWith("/dist/");
8581
+ }
8569
8582
  if (existsSync20(webDir)) {
8570
8583
  await app.register(fastifyStatic, {
8571
8584
  root: webDir,
8572
8585
  prefix: "/",
8573
- decorateReply: false,
8574
8586
  index: false
8575
8587
  });
8576
8588
  }
@@ -8591,17 +8603,21 @@ async function startServer(opts) {
8591
8603
  app.get("/index-v2-pixel.html", (_req, reply) => {
8592
8604
  reply.redirect("/pixel");
8593
8605
  });
8606
+ app.get("/", (_req, reply) => {
8607
+ return sendSpaEntry(reply);
8608
+ });
8609
+ app.get("/studio", (_req, reply) => {
8610
+ return sendSpaEntry(reply);
8611
+ });
8612
+ app.get("/pixel", (_req, reply) => {
8613
+ return sendSpaEntry(reply);
8614
+ });
8594
8615
  app.setNotFoundHandler((req, reply) => {
8595
- if (req.url.startsWith("/api/")) {
8616
+ if (req.url.startsWith("/api/") || req.url.startsWith("/ws") || isAssetRequest(req.url)) {
8596
8617
  reply.code(404).send({ error: "Not found" });
8597
8618
  return;
8598
8619
  }
8599
- const builtIndexPath = join17(webDir, "dist", "index.html");
8600
- if (existsSync20(builtIndexPath)) {
8601
- reply.sendFile("dist/index.html");
8602
- } else {
8603
- reply.code(200).header("content-type", "text/html").send(getEmbeddedHtml());
8604
- }
8620
+ return sendSpaEntry(reply);
8605
8621
  });
8606
8622
  try {
8607
8623
  await app.listen({ port: opts.port, host: opts.host });