@blinkk/root 3.5.2 → 3.5.3

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/functions.js CHANGED
@@ -15,15 +15,27 @@ import "./chunk-WX62JK5E.js";
15
15
  import path from "node:path";
16
16
  import { onRequest } from "firebase-functions/v2/https";
17
17
  function server(options) {
18
- let rootServer;
18
+ let rootServerPromise = null;
19
19
  const rootDir = path.resolve(options?.rootDir || process.cwd());
20
+ function getRootServer() {
21
+ if (!rootServerPromise) {
22
+ const createServer = options?.mode === "preview" ? createPreviewServer : createProdServer;
23
+ rootServerPromise = createServer({ rootDir }).catch((err) => {
24
+ rootServerPromise = null;
25
+ throw err;
26
+ });
27
+ }
28
+ return rootServerPromise;
29
+ }
20
30
  return onRequest(options?.httpsOptions || {}, async (req, res) => {
21
- if (!rootServer) {
22
- if (options?.mode === "preview") {
23
- rootServer = await createPreviewServer({ rootDir });
24
- } else {
25
- rootServer = await createProdServer({ rootDir });
26
- }
31
+ let rootServer;
32
+ try {
33
+ rootServer = await getRootServer();
34
+ } catch (err) {
35
+ console.error("failed to start the root.js server:");
36
+ console.error(err);
37
+ res.status(500).set({ "Content-Type": "text/plain" }).end("500");
38
+ return;
27
39
  }
28
40
  await rootServer(req, res);
29
41
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/functions/server.ts"],
4
- "sourcesContent": ["import path from 'node:path';\nimport {HttpsOptions, onRequest} from 'firebase-functions/v2/https';\nimport {createPreviewServer, createProdServer} from '../cli/cli.js';\nimport {Server} from '../core/types.js';\n\nexport interface ProdServerOptions {\n rootDir?: string;\n mode?: 'preview' | 'production';\n httpsOptions?: HttpsOptions;\n}\n\n/**\n * Firebase Function that runs a Root.js server running in SSR mode.\n */\nexport function server(options?: ProdServerOptions) {\n let rootServer: Server;\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n return onRequest(options?.httpsOptions || {}, async (req, res) => {\n if (!rootServer) {\n if (options?.mode === 'preview') {\n rootServer = await createPreviewServer({rootDir});\n } else {\n rootServer = await createProdServer({rootDir});\n }\n }\n await rootServer(req, res);\n });\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA,OAAO,UAAU;AACjB,SAAsB,iBAAgB;AAa/B,SAAS,OAAO,SAA6B;AAClD,MAAI;AACJ,QAAM,UAAU,KAAK,QAAQ,SAAS,WAAW,QAAQ,IAAI,CAAC;AAC9D,SAAO,UAAU,SAAS,gBAAgB,CAAC,GAAG,OAAO,KAAK,QAAQ;AAChE,QAAI,CAAC,YAAY;AACf,UAAI,SAAS,SAAS,WAAW;AAC/B,qBAAa,MAAM,oBAAoB,EAAC,QAAO,CAAC;AAAA,MAClD,OAAO;AACL,qBAAa,MAAM,iBAAiB,EAAC,QAAO,CAAC;AAAA,MAC/C;AAAA,IACF;AACA,UAAM,WAAW,KAAK,GAAG;AAAA,EAC3B,CAAC;AACH;",
4
+ "sourcesContent": ["import path from 'node:path';\nimport {HttpsOptions, onRequest} from 'firebase-functions/v2/https';\nimport {createPreviewServer, createProdServer} from '../cli/cli.js';\nimport {Server} from '../core/types.js';\n\nexport interface ProdServerOptions {\n rootDir?: string;\n mode?: 'preview' | 'production';\n httpsOptions?: HttpsOptions;\n}\n\n/**\n * Firebase Function that runs a Root.js server running in SSR mode.\n */\nexport function server(options?: ProdServerOptions) {\n let rootServerPromise: Promise<Server> | null = null;\n const rootDir = path.resolve(options?.rootDir || process.cwd());\n\n // Instances serve many concurrent requests, so the server is created once\n // and shared by every request that arrives while it is still starting up.\n // A failed startup is cleared so that the next request retries it.\n function getRootServer(): Promise<Server> {\n if (!rootServerPromise) {\n const createServer =\n options?.mode === 'preview' ? createPreviewServer : createProdServer;\n rootServerPromise = createServer({rootDir}).catch((err) => {\n rootServerPromise = null;\n throw err;\n });\n }\n return rootServerPromise;\n }\n\n return onRequest(options?.httpsOptions || {}, async (req, res) => {\n let rootServer: Server;\n try {\n rootServer = await getRootServer();\n } catch (err) {\n console.error('failed to start the root.js server:');\n console.error(err);\n res.status(500).set({'Content-Type': 'text/plain'}).end('500');\n return;\n }\n await rootServer(req, res);\n });\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA,OAAO,UAAU;AACjB,SAAsB,iBAAgB;AAa/B,SAAS,OAAO,SAA6B;AAClD,MAAI,oBAA4C;AAChD,QAAM,UAAU,KAAK,QAAQ,SAAS,WAAW,QAAQ,IAAI,CAAC;AAK9D,WAAS,gBAAiC;AACxC,QAAI,CAAC,mBAAmB;AACtB,YAAM,eACJ,SAAS,SAAS,YAAY,sBAAsB;AACtD,0BAAoB,aAAa,EAAC,QAAO,CAAC,EAAE,MAAM,CAAC,QAAQ;AACzD,4BAAoB;AACpB,cAAM;AAAA,MACR,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AAEA,SAAO,UAAU,SAAS,gBAAgB,CAAC,GAAG,OAAO,KAAK,QAAQ;AAChE,QAAI;AACJ,QAAI;AACF,mBAAa,MAAM,cAAc;AAAA,IACnC,SAAS,KAAK;AACZ,cAAQ,MAAM,qCAAqC;AACnD,cAAQ,MAAM,GAAG;AACjB,UAAI,OAAO,GAAG,EAAE,IAAI,EAAC,gBAAgB,aAAY,CAAC,EAAE,IAAI,KAAK;AAC7D;AAAA,IACF;AACA,UAAM,WAAW,KAAK,GAAG;AAAA,EAC3B,CAAC;AACH;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkk/root",
3
- "version": "3.5.2",
3
+ "version": "3.5.3",
4
4
  "author": "s@blinkk.com",
5
5
  "license": "MIT",
6
6
  "engines": {