fix: inject templates storage into API routes
This commit is contained in:
parent
fff24a08ed
commit
2c18fca719
@ -5,9 +5,14 @@ import { extractSchema } from '../engine/schema';
|
||||
import { PrinterConnector } from '../printer/connector';
|
||||
import type { Template } from '../types/template';
|
||||
|
||||
const templates = new Map<string, Template>();
|
||||
// 模板存储 - 由外部注入
|
||||
let templates = new Map<string, Template>();
|
||||
let printerConnector: PrinterConnector | null = null;
|
||||
|
||||
export function setTemplatesStorage(storage: Map<string, Template>) {
|
||||
templates = storage;
|
||||
}
|
||||
|
||||
function getPrinter(): PrinterConnector {
|
||||
if (!printerConnector) {
|
||||
const ip = process.env.PRINTER_IP || '192.168.1.100';
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
import { Hono } from 'hono';
|
||||
import { serveStatic } from 'hono/bun';
|
||||
import { apiRoutes } from './api/routes';
|
||||
import { apiRoutes, setTemplatesStorage } from './api/routes';
|
||||
import { loadExampleTemplates } from './config/loader';
|
||||
|
||||
// 加载示例模板
|
||||
const templates = await loadExampleTemplates();
|
||||
console.log(`📋 Loaded ${templates.size} example templates`);
|
||||
|
||||
// 注入模板存储到 API 路由
|
||||
setTemplatesStorage(templates);
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
// 静态文件服务(Web 界面)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user