mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 21:00:41 +00:00
feat: implement database initialization in StorageService
This commit is contained in:
+16
-1
@@ -1,9 +1,24 @@
|
||||
import { Env } from './types';
|
||||
import { handleRequest } from './router';
|
||||
import { StorageService } from './services/storage';
|
||||
|
||||
// Global flag to track if database has been initialized in this worker instance
|
||||
let dbInitialized = false;
|
||||
|
||||
export default {
|
||||
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
|
||||
// Auto-initialize database on first request
|
||||
if (!dbInitialized) {
|
||||
try {
|
||||
const storage = new StorageService(env.DB);
|
||||
await storage.initializeDatabase();
|
||||
dbInitialized = true;
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize database:', error);
|
||||
// Continue anyway - the error will surface when actual DB operations are attempted
|
||||
}
|
||||
}
|
||||
|
||||
return handleRequest(request, env);
|
||||
return handleRequest(request, env);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user