fix: fallback to in-memory state when convex functions are unavailable
This commit is contained in:
@@ -4,6 +4,7 @@ const http = require("node:http");
|
||||
const { buildApp } = require("./app");
|
||||
const { config } = require("./config");
|
||||
const { ConvexStateStore } = require("./lib/convex-state-store");
|
||||
const { InMemoryStateStore } = require("./lib/state-store");
|
||||
const { createLogger } = require("./lib/logger");
|
||||
|
||||
function readBody(req) {
|
||||
@@ -81,13 +82,23 @@ function createMutationPersister({ stateStore, logger = console }) {
|
||||
}
|
||||
|
||||
async function createRuntime({ runtimeConfig = config, logger = console, stateStore = null } = {}) {
|
||||
const effectiveStateStore = stateStore || new ConvexStateStore({
|
||||
let effectiveStateStore = stateStore || new ConvexStateStore({
|
||||
deploymentUrl: runtimeConfig.convexDeploymentUrl,
|
||||
authToken: runtimeConfig.convexAuthToken,
|
||||
readFunction: runtimeConfig.convexStateQuery,
|
||||
writeFunction: runtimeConfig.convexStateMutation,
|
||||
});
|
||||
const initialState = await effectiveStateStore.load();
|
||||
let initialState;
|
||||
try {
|
||||
initialState = await effectiveStateStore.load();
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
{ err: error },
|
||||
"failed to initialize configured state store; falling back to in-memory state",
|
||||
);
|
||||
effectiveStateStore = new InMemoryStateStore();
|
||||
initialState = await effectiveStateStore.load();
|
||||
}
|
||||
const persister = createMutationPersister({ stateStore: effectiveStateStore, logger });
|
||||
|
||||
const app = buildApp({
|
||||
|
||||
Reference in New Issue
Block a user