streamby-core 0.29.4 → 0.29.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.
|
@@ -36,7 +36,24 @@ function createStreamByRouter(config) {
|
|
|
36
36
|
const router = express_1.default.Router();
|
|
37
37
|
if (config.encrypt)
|
|
38
38
|
(0, encryption_1.setEncryptionKey)(config.encrypt);
|
|
39
|
-
|
|
39
|
+
// Establish DB connections asynchronously (Postgres/Mongo + schema migrations).
|
|
40
|
+
// Until they're ready, HOLD incoming requests instead of letting them through —
|
|
41
|
+
// route handlers resolve projects/exports (e.g. the /menu-list export) against a
|
|
42
|
+
// live connection, so hitting them before startup finishes would 404. This gate
|
|
43
|
+
// makes the client's fetch wait for StreamBy's instances to come up.
|
|
44
|
+
let ready = false;
|
|
45
|
+
const readyPromise = (0, connectionManager_1.initConnections)(config.databases || [])
|
|
46
|
+
.catch((err) => {
|
|
47
|
+
console.error('❌ StreamBy: failed to initialize database connections:', err);
|
|
48
|
+
})
|
|
49
|
+
.finally(() => {
|
|
50
|
+
ready = true;
|
|
51
|
+
});
|
|
52
|
+
router.use((_req, _res, next) => {
|
|
53
|
+
if (ready)
|
|
54
|
+
return next();
|
|
55
|
+
readyPromise.then(() => next());
|
|
56
|
+
});
|
|
40
57
|
const adapter = config.adapter || (0, storage_1.createStorageProvider)(config.storageProviders);
|
|
41
58
|
if (config.databases) {
|
|
42
59
|
const allDbIds = config.databases.map(db => db.id);
|