@backtest-kit/ui 0.0.1

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.
@@ -0,0 +1,1320 @@
1
+ 'use strict';
2
+
3
+ var http = require('http');
4
+ var functoolsKit = require('functools-kit');
5
+ var micro = require('micro');
6
+ var Router = require('router');
7
+ var finalhandler = require('finalhandler');
8
+ var serveHandler = require('serve-handler');
9
+ var os = require('os');
10
+ var diKit = require('di-kit');
11
+ var backtestKit = require('backtest-kit');
12
+ var fs = require('fs/promises');
13
+ var path = require('path');
14
+ var module$1 = require('module');
15
+ var fs$1 = require('fs');
16
+
17
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
18
+ const CC_WWWROOT_PATH = process.env.CC_WWWROOT_PATH || "";
19
+ const CC_WWWROOT_HOST = process.env.CC_WWWROOT_HOST || "0.0.0.0";
20
+ const CC_WWWROOT_PORT = parseInt(process.env.CC_WWWROOT_PORT) || 60050;
21
+ const CC_ENABLE_MOCK = !!parseInt(process.env.CC_ENABLE_MOCK) || false;
22
+
23
+ const router$6 = Router({
24
+ params: true,
25
+ });
26
+ router$6.get("/api/v1/health/health_check", async (req, res) => {
27
+ const [cpuLoad] = os.loadavg();
28
+ return await micro.send(res, 200, {
29
+ uptime: process.uptime(),
30
+ memoryUsage: process.memoryUsage(),
31
+ cpuLoad,
32
+ pid: process.pid,
33
+ });
34
+ });
35
+
36
+ function omit(obj, ...keys) {
37
+ const keySet = new Set(keys);
38
+ return Object.keys(obj).reduce((acc, key) => {
39
+ if (keySet.has(key)) {
40
+ return acc;
41
+ }
42
+ const value = obj[key];
43
+ if (functoolsKit.isObject(value)) {
44
+ acc[key] = omit(value, ...keys);
45
+ }
46
+ else {
47
+ acc[key] = value;
48
+ }
49
+ return acc;
50
+ }, {});
51
+ }
52
+
53
+ const { provide, inject, init, override } = diKit.createActivator("ui");
54
+
55
+ const baseServices$1 = {
56
+ loggerService: Symbol("loggerService"),
57
+ exchangeService: Symbol('exchangeService'),
58
+ };
59
+ const connectionServices$1 = {
60
+ symbolConnectionService: Symbol("symbolConnectionService"),
61
+ };
62
+ const metaServices$1 = {
63
+ symbolMetaService: Symbol("symbolMetaService"),
64
+ };
65
+ const mockServices$1 = {
66
+ notificationMockService: Symbol("notificationMockService"),
67
+ storageMockService: Symbol("storageMockService"),
68
+ exchangeMockService: Symbol("exchangeMockService"),
69
+ };
70
+ const viewServices$1 = {
71
+ notificationViewService: Symbol("notificationViewService"),
72
+ storageViewService: Symbol("storageViewService"),
73
+ exchangeViewService: Symbol("exchangeViewService"),
74
+ };
75
+ const TYPES = {
76
+ ...baseServices$1,
77
+ ...connectionServices$1,
78
+ ...metaServices$1,
79
+ ...mockServices$1,
80
+ ...viewServices$1,
81
+ };
82
+
83
+ const INTERVAL_MINUTES = {
84
+ "1m": 1,
85
+ "3m": 3,
86
+ "5m": 5,
87
+ "15m": 15,
88
+ "30m": 30,
89
+ "1h": 60,
90
+ "2h": 120,
91
+ "4h": 240,
92
+ "6h": 360,
93
+ "8h": 480,
94
+ };
95
+ const STEP_TICKS = {
96
+ "1m": 960,
97
+ "3m": 960,
98
+ "5m": 960,
99
+ "15m": 960,
100
+ "30m": 960,
101
+ "1h": 960,
102
+ "2h": 960,
103
+ "4h": 960,
104
+ "6h": 960,
105
+ "8h": 960,
106
+ };
107
+ class ExchangeService {
108
+ constructor() {
109
+ this.loggerService = inject(TYPES.loggerService);
110
+ this.getRangeCandles = async (dto) => {
111
+ this.loggerService.log("exchangeService getRangeCandles", {
112
+ dto,
113
+ });
114
+ const step = INTERVAL_MINUTES[dto.interval];
115
+ const tick = STEP_TICKS[dto.interval];
116
+ if (!step || !tick) {
117
+ throw new Error(`Unsupported interval: ${dto.interval}`);
118
+ }
119
+ const offsetMs = tick * step * 60 * 1000;
120
+ const sDate = dto.signalStartTime - offsetMs;
121
+ const eDate = Math.min(dto.signalStopTime + offsetMs, Date.now() - 1);
122
+ return await backtestKit.Exchange.getRawCandles(dto.symbol, dto.interval, {
123
+ exchangeName: dto.exchangeName,
124
+ }, undefined, sDate, eDate);
125
+ };
126
+ this.getPointCandles = async (dto) => {
127
+ this.loggerService.log("exchangeService getPointCandles", {
128
+ dto,
129
+ });
130
+ const step = INTERVAL_MINUTES[dto.interval];
131
+ const tick = STEP_TICKS[dto.interval];
132
+ if (!step || !tick) {
133
+ throw new Error(`Unsupported interval: ${dto.interval}`);
134
+ }
135
+ const offsetMs = tick * step * 60 * 1000;
136
+ const sDate = dto.currentTime - offsetMs;
137
+ const eDate = Math.min(dto.currentTime + offsetMs, Date.now() - 1);
138
+ return await backtestKit.Exchange.getRawCandles(dto.symbol, dto.interval, {
139
+ exchangeName: dto.exchangeName,
140
+ }, undefined, sDate, eDate);
141
+ };
142
+ }
143
+ }
144
+
145
+ const NOOP_LOGGER = {
146
+ log() {
147
+ },
148
+ debug() {
149
+ },
150
+ info() {
151
+ },
152
+ warn() {
153
+ },
154
+ };
155
+ class LoggerService {
156
+ constructor() {
157
+ this._commonLogger = NOOP_LOGGER;
158
+ this.log = async (topic, ...args) => {
159
+ await this._commonLogger.log(topic, ...args);
160
+ };
161
+ this.debug = async (topic, ...args) => {
162
+ await this._commonLogger.debug(topic, ...args);
163
+ };
164
+ this.info = async (topic, ...args) => {
165
+ await this._commonLogger.info(topic, ...args);
166
+ };
167
+ this.warn = async (topic, ...args) => {
168
+ await this._commonLogger.warn(topic, ...args);
169
+ };
170
+ this.setLogger = (logger) => {
171
+ this._commonLogger = logger;
172
+ };
173
+ }
174
+ }
175
+
176
+ const MOCK_PATH$1 = "./mock/notifications.json";
177
+ const READ_NOTIFICATION_LIST_FN = functoolsKit.singleshot(async () => {
178
+ const data = await fs.readFile(MOCK_PATH$1, "utf-8");
179
+ return JSON.parse(data);
180
+ });
181
+ const DEFAULT_LIMIT$1 = 25;
182
+ const DEFAULT_OFFSET$1 = 0;
183
+ const CREATE_FILTER_LIST_FN$1 = (filterData) => Object.keys(filterData).map((key) => (row) => new RegExp(filterData[key], "i").test(row[key]));
184
+ class NotificationMockService {
185
+ constructor() {
186
+ this.loggerService = inject(TYPES.loggerService);
187
+ this.findByFilter = async (filterData, limit = DEFAULT_LIMIT$1, offset = DEFAULT_OFFSET$1) => {
188
+ this.loggerService.log("notificationMockService findByFilter", {
189
+ filterData,
190
+ limit,
191
+ offset,
192
+ });
193
+ const iter = functoolsKit.pickDocuments(limit, offset);
194
+ const filterList = CREATE_FILTER_LIST_FN$1(filterData);
195
+ for (const notification of await this.getList()) {
196
+ let isOk = true;
197
+ for (const filterFn of filterList) {
198
+ isOk = isOk && filterFn(notification);
199
+ }
200
+ if (!isOk) {
201
+ continue;
202
+ }
203
+ if (iter([notification]).done) {
204
+ break;
205
+ }
206
+ }
207
+ return iter().rows;
208
+ };
209
+ this.getList = async () => {
210
+ this.loggerService.log("notificationMockService getList");
211
+ return await READ_NOTIFICATION_LIST_FN();
212
+ };
213
+ this.getOne = async (id) => {
214
+ this.loggerService.log("notificationMockService getOne");
215
+ const notificationList = await this.getList();
216
+ return notificationList.find((item) => item.id === id) ?? null;
217
+ };
218
+ }
219
+ }
220
+
221
+ const MOCK_PATH = "./mock/db";
222
+ const READ_BACKTEST_STORAGE_FN = functoolsKit.singleshot(async () => {
223
+ const dbPath = path.join(process.cwd(), MOCK_PATH);
224
+ const files = await fs.readdir(dbPath);
225
+ const signals = [];
226
+ for (const file of files) {
227
+ if (!file.endsWith(".json")) {
228
+ continue;
229
+ }
230
+ const filePath = path.join(dbPath, file);
231
+ signals.push(JSON.parse(await fs.readFile(filePath, "utf-8")));
232
+ }
233
+ return signals;
234
+ });
235
+ class StorageMockService {
236
+ constructor() {
237
+ this.loggerService = inject(TYPES.loggerService);
238
+ this.findSignalById = async (signalId) => {
239
+ this.loggerService.log("storageMockService findSignalById", {
240
+ signalId,
241
+ });
242
+ const signalList = await READ_BACKTEST_STORAGE_FN();
243
+ const signalMap = new Map(signalList.map((signal) => [signal.id, signal]));
244
+ const signalValue = signalMap.get(signalId);
245
+ return signalValue ?? null;
246
+ };
247
+ this.listSignalLive = async () => {
248
+ this.loggerService.log("storageMockService listSignalLive");
249
+ return Promise.resolve([]);
250
+ };
251
+ this.listSignalBacktest = async () => {
252
+ this.loggerService.log("storageMockService listSignalBacktest");
253
+ return await READ_BACKTEST_STORAGE_FN();
254
+ };
255
+ }
256
+ }
257
+
258
+ class ExchangeMockService {
259
+ constructor() {
260
+ this.loggerService = inject(TYPES.loggerService);
261
+ this.storageMockService = inject(TYPES.storageMockService);
262
+ this.exchangeService = inject(TYPES.exchangeService);
263
+ this.getSignalCandles = async (signalId, interval) => {
264
+ this.loggerService.log("exchangeMockService getSignalCandles", {
265
+ signalId,
266
+ interval,
267
+ });
268
+ const signal = await this.storageMockService.findSignalById(signalId);
269
+ if (!signal) {
270
+ throw new Error(`Signal with ID ${signalId} not found`);
271
+ }
272
+ const { pendingAt, scheduledAt, createdAt = pendingAt || scheduledAt, updatedAt, } = signal;
273
+ return await this.exchangeService.getRangeCandles({
274
+ symbol: signal.symbol,
275
+ exchangeName: signal.exchangeName,
276
+ signalStartTime: createdAt,
277
+ signalStopTime: updatedAt,
278
+ interval,
279
+ });
280
+ };
281
+ }
282
+ }
283
+
284
+ const DEFAULT_LIMIT = 25;
285
+ const DEFAULT_OFFSET = 0;
286
+ const CREATE_FILTER_LIST_FN = (filterData) => Object.keys(filterData).map((key) => (row) => new RegExp(filterData[key], "i").test(row[key]));
287
+ class NotificationViewService {
288
+ constructor() {
289
+ this.loggerService = inject(TYPES.loggerService);
290
+ this.notificationMockService = inject(TYPES.notificationMockService);
291
+ this.findByFilter = async (filterData, limit = DEFAULT_LIMIT, offset = DEFAULT_OFFSET) => {
292
+ this.loggerService.log("notificationViewService findByFilter", {
293
+ filterData,
294
+ limit,
295
+ offset,
296
+ });
297
+ if (CC_ENABLE_MOCK) {
298
+ return await this.notificationMockService.findByFilter(filterData, limit, offset);
299
+ }
300
+ const iter = functoolsKit.pickDocuments(limit, offset);
301
+ const filterList = CREATE_FILTER_LIST_FN(filterData);
302
+ for (const notification of await this.getList()) {
303
+ let isOk = true;
304
+ for (const filterFn of filterList) {
305
+ isOk = isOk && filterFn(notification);
306
+ }
307
+ if (!isOk) {
308
+ continue;
309
+ }
310
+ if (iter([notification]).done) {
311
+ break;
312
+ }
313
+ }
314
+ return iter().rows;
315
+ };
316
+ this.getList = async () => {
317
+ this.loggerService.log("notificationViewService getList");
318
+ if (CC_ENABLE_MOCK) {
319
+ return await this.notificationMockService.getList();
320
+ }
321
+ const notificationList = [];
322
+ for (const notification of await backtestKit.Notification.getData(false)) {
323
+ notificationList.push(notification);
324
+ }
325
+ for (const notification of await backtestKit.Notification.getData(true)) {
326
+ notificationList.push(notification);
327
+ }
328
+ return notificationList;
329
+ };
330
+ this.getOne = async (id) => {
331
+ this.loggerService.log("notificationViewService getOne", {
332
+ id,
333
+ });
334
+ if (CC_ENABLE_MOCK) {
335
+ return await this.notificationMockService.getOne(id);
336
+ }
337
+ const notificationList = await this.getList();
338
+ return notificationList.find((item) => item.id === id) ?? null;
339
+ };
340
+ this.init = functoolsKit.singleshot(async () => {
341
+ this.loggerService.log("notificationViewService init");
342
+ if (CC_ENABLE_MOCK) {
343
+ return;
344
+ }
345
+ backtestKit.Notification.enable();
346
+ });
347
+ }
348
+ }
349
+
350
+ class StorageViewService {
351
+ constructor() {
352
+ this.loggerService = inject(TYPES.loggerService);
353
+ this.storageMockService = inject(TYPES.storageMockService);
354
+ this.findSignalById = async (signalId) => {
355
+ this.loggerService.log("storageViewService findSignalById", {
356
+ signalId,
357
+ });
358
+ if (CC_ENABLE_MOCK) {
359
+ return await this.storageMockService.findSignalById(signalId);
360
+ }
361
+ return await backtestKit.Storage.findSignalById(signalId);
362
+ };
363
+ this.listSignalLive = async () => {
364
+ this.loggerService.log("storageViewService listSignalLive");
365
+ if (CC_ENABLE_MOCK) {
366
+ return await this.storageMockService.listSignalLive();
367
+ }
368
+ return await backtestKit.Storage.listSignalLive();
369
+ };
370
+ this.listSignalBacktest = async () => {
371
+ this.loggerService.log("storageViewService listSignalBacktest");
372
+ if (CC_ENABLE_MOCK) {
373
+ return await this.storageMockService.listSignalBacktest();
374
+ }
375
+ return await backtestKit.Storage.listSignalBacktest();
376
+ };
377
+ this.init = functoolsKit.singleshot(async () => {
378
+ this.loggerService.log("storageViewService init");
379
+ if (CC_ENABLE_MOCK) {
380
+ return;
381
+ }
382
+ backtestKit.Storage.enable();
383
+ });
384
+ }
385
+ }
386
+
387
+ class ExchangeViewService {
388
+ constructor() {
389
+ this.loggerService = inject(TYPES.loggerService);
390
+ this.storageViewService = inject(TYPES.storageViewService);
391
+ this.exchangeService = inject(TYPES.exchangeService);
392
+ this.exchangeMockService = inject(TYPES.exchangeMockService);
393
+ this.getSignalCandles = async (signalId, interval) => {
394
+ this.loggerService.log("exchangeViewService getCandles", {
395
+ signalId,
396
+ interval,
397
+ });
398
+ if (CC_ENABLE_MOCK) {
399
+ return await this.exchangeMockService.getSignalCandles(signalId, interval);
400
+ }
401
+ const signal = await this.storageViewService.findSignalById(signalId);
402
+ if (!signal) {
403
+ throw new Error(`Signal with ID ${signalId} not found`);
404
+ }
405
+ const { pendingAt, scheduledAt, createdAt = pendingAt || scheduledAt, updatedAt, } = signal;
406
+ return await this.exchangeService.getRangeCandles({
407
+ symbol: signal.symbol,
408
+ exchangeName: signal.exchangeName,
409
+ signalStartTime: createdAt,
410
+ signalStopTime: updatedAt,
411
+ interval,
412
+ });
413
+ };
414
+ }
415
+ }
416
+
417
+ const symbol_list = [
418
+ {
419
+ icon: "/icon/btc.png",
420
+ logo: "/icon/128/btc.png",
421
+ symbol: "BTCUSDT",
422
+ displayName: "Bitcoin",
423
+ color: "#F7931A",
424
+ priority: 50,
425
+ description: functoolsKit.str.newline("Bitcoin - the first and most popular cryptocurrency", "Digital gold with a limited supply of 21 million coins", "Used as a reserve asset and a store of value", "Highly liquid market with large trading volumes"),
426
+ },
427
+ {
428
+ icon: "/icon/eth.png",
429
+ logo: "/icon/128/eth.png",
430
+ symbol: "ETHUSDT",
431
+ color: "#6F42C1",
432
+ displayName: "Ethereum",
433
+ priority: 50,
434
+ description: functoolsKit.str.newline("Ethereum - a blockchain platform for smart contracts", "The foundation of DeFi and NFT ecosystems", "Transition to Proof-of-Stake (Ethereum 2.0)", "Second largest cryptocurrency by market capitalization"),
435
+ },
436
+ {
437
+ icon: "/icon/bnb.png",
438
+ logo: "/icon/128/bnb.png",
439
+ symbol: "BNBUSDT",
440
+ color: "#F3BA2F",
441
+ displayName: "BNB",
442
+ priority: 50,
443
+ description: functoolsKit.str.newline("Binance Coin - the native token of the largest exchange", "Used for trading fee discounts", "Core of BNB Smart Chain for decentralized apps (DApps)", "Regular token burns reduce the circulating supply"),
444
+ },
445
+ {
446
+ icon: "/icon/xrp.png",
447
+ logo: "/icon/128/xrp.png",
448
+ symbol: "XRPUSDT",
449
+ color: "#23292F",
450
+ displayName: "Ripple",
451
+ priority: 100,
452
+ description: functoolsKit.str.newline("XRP - a digital asset for international payments", "Fast and low-cost cross-border transfers", "Used by banks and financial institutions", "Low fees and transaction times of 3-5 seconds"),
453
+ },
454
+ {
455
+ icon: "/icon/sol.png",
456
+ logo: "/icon/128/sol.png",
457
+ symbol: "SOLUSDT",
458
+ color: "#00e676",
459
+ displayName: "Solana",
460
+ priority: 100,
461
+ description: functoolsKit.str.newline("Solana - a high-performance blockchain", "Up to 65,000 transactions per second", "A popular platform for NFT and DeFi projects", "Low fees and fast transaction confirmation"),
462
+ },
463
+ ];
464
+
465
+ const require$3 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
466
+ const getSymbolList = functoolsKit.singleshot(() => {
467
+ try {
468
+ const modulePath = require$3.resolve(path.join(process.cwd(), `./config/symbol.config.cjs`));
469
+ console.log(`Using ${modulePath} implementation as symbol.config.cjs`);
470
+ return require$3(modulePath);
471
+ }
472
+ catch (error) {
473
+ console.log(`Using default implementation for symbol.config.cjs`, error);
474
+ return symbol_list;
475
+ }
476
+ });
477
+ class SymbolConnectionService {
478
+ constructor() {
479
+ this.loggerService = inject(TYPES.loggerService);
480
+ this.getSymbolList = functoolsKit.singleshot(async () => {
481
+ this.loggerService.log("symbolConnectionService getSymbolList");
482
+ const symbolListRaw = await getSymbolList();
483
+ const uniqueSymbols = new Set();
484
+ const symbolList = symbolListRaw
485
+ .filter((item) => {
486
+ if (uniqueSymbols.has(item.symbol)) {
487
+ return false;
488
+ }
489
+ uniqueSymbols.add(item.symbol);
490
+ return true;
491
+ })
492
+ .map(({ priority, displayName, symbol, logo, icon, ...other }, idx) => ({
493
+ symbol,
494
+ icon,
495
+ logo: logo ?? icon,
496
+ priority: priority ?? idx,
497
+ displayName: displayName ?? symbol,
498
+ index: idx,
499
+ ...other,
500
+ }));
501
+ symbolList.sort(({ priority: a_p, index: a_x }, { priority: b_p, index: b_x }) => b_p - a_p || a_x - b_x);
502
+ return symbolList;
503
+ });
504
+ this.init = functoolsKit.singleshot(async () => {
505
+ this.loggerService.log("symbolConnectionService init");
506
+ getSymbolList();
507
+ });
508
+ }
509
+ }
510
+
511
+ class SymbolMetaService {
512
+ constructor() {
513
+ this.symbolConnectionService = inject(TYPES.symbolConnectionService);
514
+ this.loggerService = inject(TYPES.loggerService);
515
+ this.getSymbolList = functoolsKit.singleshot(async () => {
516
+ this.loggerService.log("symbolMetaService getSymbolList");
517
+ const symbolList = await this.symbolConnectionService.getSymbolList();
518
+ return symbolList.map(({ symbol }) => symbol);
519
+ });
520
+ this.getSymbolMap = functoolsKit.singleshot(async () => {
521
+ this.loggerService.log("symbolMetaService getSymbolMap");
522
+ const symbolList = await this.symbolConnectionService.getSymbolList();
523
+ return symbolList.reduce((acm, { symbol, ...other }) => ({
524
+ ...acm,
525
+ [symbol]: { symbol, ...other },
526
+ }), {});
527
+ });
528
+ this.getSymbol = functoolsKit.memoize(([symbol]) => `${symbol}`, async (symbol) => {
529
+ this.loggerService.log("symbolMetaService getSymbol", {
530
+ symbol,
531
+ });
532
+ const symbolList = await this.symbolConnectionService.getSymbolList();
533
+ const target = symbolList.find((item) => item.symbol === symbol);
534
+ if (!target) {
535
+ throw new Error(`symbolMetaService getSymbol no item found symbol=${symbol}`);
536
+ }
537
+ return target;
538
+ });
539
+ }
540
+ }
541
+
542
+ {
543
+ provide(TYPES.loggerService, () => new LoggerService());
544
+ provide(TYPES.exchangeService, () => new ExchangeService());
545
+ }
546
+ {
547
+ provide(TYPES.symbolConnectionService, () => new SymbolConnectionService());
548
+ }
549
+ {
550
+ provide(TYPES.symbolMetaService, () => new SymbolMetaService());
551
+ }
552
+ {
553
+ provide(TYPES.notificationMockService, () => new NotificationMockService());
554
+ provide(TYPES.storageMockService, () => new StorageMockService());
555
+ provide(TYPES.exchangeMockService, () => new ExchangeMockService());
556
+ }
557
+ {
558
+ provide(TYPES.notificationViewService, () => new NotificationViewService());
559
+ provide(TYPES.storageViewService, () => new StorageViewService());
560
+ provide(TYPES.exchangeViewService, () => new ExchangeViewService());
561
+ }
562
+
563
+ const baseServices = {
564
+ loggerService: inject(TYPES.loggerService),
565
+ exchangeService: inject(TYPES.exchangeService),
566
+ };
567
+ const connectionServices = {
568
+ symbolConnectionService: inject(TYPES.symbolConnectionService),
569
+ };
570
+ const metaServices = {
571
+ symbolMetaService: inject(TYPES.symbolMetaService),
572
+ };
573
+ const mockServices = {
574
+ notificationMockService: inject(TYPES.notificationMockService),
575
+ storageMockService: inject(TYPES.storageMockService),
576
+ exchangeMockService: inject(TYPES.exchangeMockService),
577
+ };
578
+ const viewServices = {
579
+ notificationViewService: inject(TYPES.notificationViewService),
580
+ storageViewService: inject(TYPES.storageViewService),
581
+ exchangeViewService: inject(TYPES.exchangeViewService),
582
+ };
583
+ const ioc = {
584
+ ...baseServices,
585
+ ...connectionServices,
586
+ ...metaServices,
587
+ ...mockServices,
588
+ ...viewServices,
589
+ };
590
+ init();
591
+
592
+ const router$5 = Router({
593
+ params: true,
594
+ });
595
+ // ExchangeMockService endpoints
596
+ router$5.post("/api/v1/mock/candles_signal", async (req, res) => {
597
+ try {
598
+ const request = await micro.json(req);
599
+ const { signalId, interval, requestId, serviceName } = request;
600
+ const data = await ioc.exchangeMockService.getSignalCandles(signalId, interval);
601
+ const result = {
602
+ data,
603
+ status: "ok",
604
+ error: "",
605
+ requestId,
606
+ serviceName,
607
+ };
608
+ ioc.loggerService.log("/api/v1/mock/candles_signal ok", {
609
+ request,
610
+ result: omit(result, "data"),
611
+ });
612
+ return await micro.send(res, 200, result);
613
+ }
614
+ catch (error) {
615
+ ioc.loggerService.log("/api/v1/mock/candles_signal error", {
616
+ error: functoolsKit.errorData(error),
617
+ });
618
+ return await micro.send(res, 200, {
619
+ status: "error",
620
+ error: functoolsKit.getErrorMessage(error),
621
+ });
622
+ }
623
+ });
624
+ router$5.post("/api/v1/mock/candles_point", async (req, res) => {
625
+ try {
626
+ const request = await micro.json(req);
627
+ const { currentTime, interval, requestId, serviceName, symbol, exchangeName } = request;
628
+ const data = await ioc.exchangeService.getPointCandles({
629
+ currentTime,
630
+ interval,
631
+ symbol,
632
+ exchangeName,
633
+ });
634
+ const result = {
635
+ data,
636
+ status: "ok",
637
+ error: "",
638
+ requestId,
639
+ serviceName,
640
+ };
641
+ ioc.loggerService.log("/api/v1/mock/candles_point ok", {
642
+ request,
643
+ result: omit(result, "data"),
644
+ });
645
+ return await micro.send(res, 200, result);
646
+ }
647
+ catch (error) {
648
+ ioc.loggerService.log("/api/v1/mock/candles_point error", {
649
+ error: functoolsKit.errorData(error),
650
+ });
651
+ return await micro.send(res, 200, {
652
+ status: "error",
653
+ error: functoolsKit.getErrorMessage(error),
654
+ });
655
+ }
656
+ });
657
+ // NotificationMockService endpoints
658
+ router$5.post("/api/v1/mock/notification_list", async (req, res) => {
659
+ try {
660
+ const request = await micro.json(req);
661
+ const { requestId, serviceName } = request;
662
+ const data = await ioc.notificationMockService.getList();
663
+ const result = {
664
+ data,
665
+ status: "ok",
666
+ error: "",
667
+ requestId,
668
+ serviceName,
669
+ };
670
+ ioc.loggerService.log("/api/v1/mock/notification_list ok", {
671
+ request,
672
+ result: omit(result, "data"),
673
+ });
674
+ return await micro.send(res, 200, result);
675
+ }
676
+ catch (error) {
677
+ ioc.loggerService.log("/api/v1/mock/notification_list error", {
678
+ error: functoolsKit.errorData(error),
679
+ });
680
+ return await micro.send(res, 200, {
681
+ status: "error",
682
+ error: functoolsKit.getErrorMessage(error),
683
+ });
684
+ }
685
+ });
686
+ router$5.post("/api/v1/mock/notification_one/:id", async (req, res) => {
687
+ try {
688
+ const request = await micro.json(req);
689
+ const { requestId, serviceName } = request;
690
+ const id = req.params.id;
691
+ const data = await ioc.notificationMockService.getOne(id);
692
+ const result = {
693
+ data,
694
+ status: "ok",
695
+ error: "",
696
+ requestId,
697
+ serviceName,
698
+ };
699
+ ioc.loggerService.log("/api/v1/mock/notification_one/:id ok", {
700
+ request,
701
+ result: omit(result, "data"),
702
+ });
703
+ return await micro.send(res, 200, result);
704
+ }
705
+ catch (error) {
706
+ ioc.loggerService.log("/api/v1/mock/notification_one/:id error", {
707
+ error: functoolsKit.errorData(error),
708
+ });
709
+ return await micro.send(res, 200, {
710
+ status: "error",
711
+ error: functoolsKit.getErrorMessage(error),
712
+ });
713
+ }
714
+ });
715
+ router$5.post("/api/v1/mock/notification_filter", async (req, res) => {
716
+ try {
717
+ const request = await micro.json(req);
718
+ const { requestId, serviceName, filterData, limit, offset } = request;
719
+ const data = await ioc.notificationMockService.findByFilter(filterData, limit, offset);
720
+ const result = {
721
+ data,
722
+ status: "ok",
723
+ error: "",
724
+ requestId,
725
+ serviceName,
726
+ };
727
+ ioc.loggerService.log("/api/v1/mock/notification_filter ok", {
728
+ request,
729
+ result: omit(result, "data"),
730
+ });
731
+ return await micro.send(res, 200, result);
732
+ }
733
+ catch (error) {
734
+ ioc.loggerService.log("/api/v1/mock/notification_filter error", {
735
+ error: functoolsKit.errorData(error),
736
+ });
737
+ return await micro.send(res, 200, {
738
+ status: "error",
739
+ error: functoolsKit.getErrorMessage(error),
740
+ });
741
+ }
742
+ });
743
+ // StorageMockService endpoints
744
+ router$5.post("/api/v1/mock/storage_one/:id", async (req, res) => {
745
+ try {
746
+ const request = await micro.json(req);
747
+ const { requestId, serviceName } = request;
748
+ const signalId = req.params.id;
749
+ const data = await ioc.storageMockService.findSignalById(signalId);
750
+ const result = {
751
+ data,
752
+ status: "ok",
753
+ error: "",
754
+ requestId,
755
+ serviceName,
756
+ };
757
+ ioc.loggerService.log("/api/v1/mock/storage_one/:id ok", {
758
+ request,
759
+ result: omit(result, "data"),
760
+ });
761
+ return await micro.send(res, 200, result);
762
+ }
763
+ catch (error) {
764
+ ioc.loggerService.log("/api/v1/mock/storage_one/:id error", {
765
+ error: functoolsKit.errorData(error),
766
+ });
767
+ return await micro.send(res, 200, {
768
+ status: "error",
769
+ error: functoolsKit.getErrorMessage(error),
770
+ });
771
+ }
772
+ });
773
+ router$5.post("/api/v1/mock/storage_list/live", async (req, res) => {
774
+ try {
775
+ const request = await micro.json(req);
776
+ const { requestId, serviceName } = request;
777
+ const data = await ioc.storageMockService.listSignalLive();
778
+ const result = {
779
+ data,
780
+ status: "ok",
781
+ error: "",
782
+ requestId,
783
+ serviceName,
784
+ };
785
+ ioc.loggerService.log("/api/v1/mock/storage_list/live ok", {
786
+ request,
787
+ result: omit(result, "data"),
788
+ });
789
+ return await micro.send(res, 200, result);
790
+ }
791
+ catch (error) {
792
+ ioc.loggerService.log("/api/v1/mock/storage_list/live error", {
793
+ error: functoolsKit.errorData(error),
794
+ });
795
+ return await micro.send(res, 200, {
796
+ status: "error",
797
+ error: functoolsKit.getErrorMessage(error),
798
+ });
799
+ }
800
+ });
801
+ router$5.post("/api/v1/mock/storage_list/backtest", async (req, res) => {
802
+ try {
803
+ const request = await micro.json(req);
804
+ const { requestId, serviceName } = request;
805
+ const data = await ioc.storageMockService.listSignalBacktest();
806
+ const result = {
807
+ data,
808
+ status: "ok",
809
+ error: "",
810
+ requestId,
811
+ serviceName,
812
+ };
813
+ ioc.loggerService.log("/api/v1/mock/storage_list/backtest ok", {
814
+ request,
815
+ result: omit(result, "data"),
816
+ });
817
+ return await micro.send(res, 200, result);
818
+ }
819
+ catch (error) {
820
+ ioc.loggerService.log("/api/v1/mock/storage_list/backtest error", {
821
+ error: functoolsKit.errorData(error),
822
+ });
823
+ return await micro.send(res, 200, {
824
+ status: "error",
825
+ error: functoolsKit.getErrorMessage(error),
826
+ });
827
+ }
828
+ });
829
+
830
+ const router$4 = Router({
831
+ params: true,
832
+ });
833
+ // ExchangeViewService endpoints
834
+ router$4.post("/api/v1/view/candles_signal", async (req, res) => {
835
+ try {
836
+ const request = await micro.json(req);
837
+ const { signalId, interval, requestId, serviceName } = request;
838
+ const data = await ioc.exchangeViewService.getSignalCandles(signalId, interval);
839
+ const result = {
840
+ data,
841
+ status: "ok",
842
+ error: "",
843
+ requestId,
844
+ serviceName,
845
+ };
846
+ ioc.loggerService.log("/api/v1/view/candles_signal ok", {
847
+ request,
848
+ result: omit(result, "data"),
849
+ });
850
+ return await micro.send(res, 200, result);
851
+ }
852
+ catch (error) {
853
+ ioc.loggerService.log("/api/v1/view/candles_signal error", {
854
+ error: functoolsKit.errorData(error),
855
+ });
856
+ return await micro.send(res, 200, {
857
+ status: "error",
858
+ error: functoolsKit.getErrorMessage(error),
859
+ });
860
+ }
861
+ });
862
+ router$4.post("/api/v1/view/candles_point", async (req, res) => {
863
+ try {
864
+ const request = await micro.json(req);
865
+ const { currentTime, interval, requestId, serviceName, symbol, exchangeName } = request;
866
+ const data = await ioc.exchangeService.getPointCandles({
867
+ currentTime,
868
+ interval,
869
+ symbol,
870
+ exchangeName,
871
+ });
872
+ const result = {
873
+ data,
874
+ status: "ok",
875
+ error: "",
876
+ requestId,
877
+ serviceName,
878
+ };
879
+ ioc.loggerService.log("/api/v1/view/candles_point ok", {
880
+ request,
881
+ result: omit(result, "data"),
882
+ });
883
+ return await micro.send(res, 200, result);
884
+ }
885
+ catch (error) {
886
+ ioc.loggerService.log("/api/v1/view/candles_point error", {
887
+ error: functoolsKit.errorData(error),
888
+ });
889
+ return await micro.send(res, 200, {
890
+ status: "error",
891
+ error: functoolsKit.getErrorMessage(error),
892
+ });
893
+ }
894
+ });
895
+ // NotificationViewService endpoints
896
+ router$4.post("/api/v1/view/notification_list", async (req, res) => {
897
+ try {
898
+ const request = await micro.json(req);
899
+ const { requestId, serviceName } = request;
900
+ const data = await ioc.notificationViewService.getList();
901
+ const result = {
902
+ data,
903
+ status: "ok",
904
+ error: "",
905
+ requestId,
906
+ serviceName,
907
+ };
908
+ ioc.loggerService.log("/api/v1/view/notification_list ok", {
909
+ request,
910
+ result: omit(result, "data"),
911
+ });
912
+ return await micro.send(res, 200, result);
913
+ }
914
+ catch (error) {
915
+ ioc.loggerService.log("/api/v1/view/notification_list error", {
916
+ error: functoolsKit.errorData(error),
917
+ });
918
+ return await micro.send(res, 200, {
919
+ status: "error",
920
+ error: functoolsKit.getErrorMessage(error),
921
+ });
922
+ }
923
+ });
924
+ router$4.post("/api/v1/view/notification_one/:id", async (req, res) => {
925
+ try {
926
+ const request = await micro.json(req);
927
+ const { requestId, serviceName } = request;
928
+ const id = req.params.id;
929
+ const data = await ioc.notificationViewService.getOne(id);
930
+ const result = {
931
+ data,
932
+ status: "ok",
933
+ error: "",
934
+ requestId,
935
+ serviceName,
936
+ };
937
+ ioc.loggerService.log("/api/v1/view/notification_one/:id ok", {
938
+ request,
939
+ result: omit(result, "data"),
940
+ });
941
+ return await micro.send(res, 200, result);
942
+ }
943
+ catch (error) {
944
+ ioc.loggerService.log("/api/v1/view/notification_one/:id error", {
945
+ error: functoolsKit.errorData(error),
946
+ });
947
+ return await micro.send(res, 200, {
948
+ status: "error",
949
+ error: functoolsKit.getErrorMessage(error),
950
+ });
951
+ }
952
+ });
953
+ router$4.post("/api/v1/view/notification_filter", async (req, res) => {
954
+ try {
955
+ const request = await micro.json(req);
956
+ const { requestId, serviceName, filterData, limit, offset } = request;
957
+ const data = await ioc.notificationViewService.findByFilter(filterData, limit, offset);
958
+ const result = {
959
+ data,
960
+ status: "ok",
961
+ error: "",
962
+ requestId,
963
+ serviceName,
964
+ };
965
+ ioc.loggerService.log("/api/v1/view/notification_filter ok", {
966
+ request,
967
+ result: omit(result, "data"),
968
+ });
969
+ return await micro.send(res, 200, result);
970
+ }
971
+ catch (error) {
972
+ ioc.loggerService.log("/api/v1/view/notification_filter error", {
973
+ error: functoolsKit.errorData(error),
974
+ });
975
+ return await micro.send(res, 200, {
976
+ status: "error",
977
+ error: functoolsKit.getErrorMessage(error),
978
+ });
979
+ }
980
+ });
981
+ // StorageViewService endpoints
982
+ router$4.post("/api/v1/view/storage_one/:id", async (req, res) => {
983
+ try {
984
+ const request = await micro.json(req);
985
+ const { requestId, serviceName } = request;
986
+ const signalId = req.params.id;
987
+ const data = await ioc.storageViewService.findSignalById(signalId);
988
+ const result = {
989
+ data,
990
+ status: "ok",
991
+ error: "",
992
+ requestId,
993
+ serviceName,
994
+ };
995
+ ioc.loggerService.log("/api/v1/view/storage_one/:id ok", {
996
+ request,
997
+ result: omit(result, "data"),
998
+ });
999
+ return await micro.send(res, 200, result);
1000
+ }
1001
+ catch (error) {
1002
+ ioc.loggerService.log("/api/v1/view/storage_one/:id error", {
1003
+ error: functoolsKit.errorData(error),
1004
+ });
1005
+ return await micro.send(res, 200, {
1006
+ status: "error",
1007
+ error: functoolsKit.getErrorMessage(error),
1008
+ });
1009
+ }
1010
+ });
1011
+ router$4.post("/api/v1/view/storage_list/live", async (req, res) => {
1012
+ try {
1013
+ const request = await micro.json(req);
1014
+ const { requestId, serviceName } = request;
1015
+ const data = await ioc.storageViewService.listSignalLive();
1016
+ const result = {
1017
+ data,
1018
+ status: "ok",
1019
+ error: "",
1020
+ requestId,
1021
+ serviceName,
1022
+ };
1023
+ ioc.loggerService.log("/api/v1/view/storage_list/live ok", {
1024
+ request,
1025
+ result: omit(result, "data"),
1026
+ });
1027
+ return await micro.send(res, 200, result);
1028
+ }
1029
+ catch (error) {
1030
+ ioc.loggerService.log("/api/v1/view/storage_list/live error", {
1031
+ error: functoolsKit.errorData(error),
1032
+ });
1033
+ return await micro.send(res, 200, {
1034
+ status: "error",
1035
+ error: functoolsKit.getErrorMessage(error),
1036
+ });
1037
+ }
1038
+ });
1039
+ router$4.post("/api/v1/view/storage_list/backtest", async (req, res) => {
1040
+ try {
1041
+ const request = await micro.json(req);
1042
+ const { requestId, serviceName } = request;
1043
+ const data = await ioc.storageViewService.listSignalBacktest();
1044
+ const result = {
1045
+ data,
1046
+ status: "ok",
1047
+ error: "",
1048
+ requestId,
1049
+ serviceName,
1050
+ };
1051
+ ioc.loggerService.log("/api/v1/view/storage_list/backtest ok", {
1052
+ request,
1053
+ result: omit(result, "data"),
1054
+ });
1055
+ return await micro.send(res, 200, result);
1056
+ }
1057
+ catch (error) {
1058
+ ioc.loggerService.log("/api/v1/view/storage_list/backtest error", {
1059
+ error: functoolsKit.errorData(error),
1060
+ });
1061
+ return await micro.send(res, 200, {
1062
+ status: "error",
1063
+ error: functoolsKit.getErrorMessage(error),
1064
+ });
1065
+ }
1066
+ });
1067
+
1068
+ const require$2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
1069
+ function getModulesPath() {
1070
+ const modulePath = require$2.resolve('@backtest-kit/ui');
1071
+ const basePath = path.dirname(modulePath);
1072
+ return path.join(basePath, "../../");
1073
+ }
1074
+
1075
+ const router$3 = Router({
1076
+ params: true,
1077
+ });
1078
+ // getModulesPath
1079
+ const ASSET_SVG = CC_ENABLE_MOCK
1080
+ ? path.join(process.cwd(), "node_modules/cryptocurrency-icons/svg/color")
1081
+ : path.join(getModulesPath(), "cryptocurrency-icons/svg/color");
1082
+ const ASSET_128 = CC_ENABLE_MOCK
1083
+ ? path.join(process.cwd(), "node_modules/cryptocurrency-icons/128/color")
1084
+ : path.join(getModulesPath(), "cryptocurrency-icons/128/color");
1085
+ const ASSET_32 = CC_ENABLE_MOCK
1086
+ ? path.join(process.cwd(), "node_modules/cryptocurrency-icons/32/color")
1087
+ : path.join(getModulesPath(), "cryptocurrency-icons/32/color");
1088
+ // File caches to avoid repeated disk reads
1089
+ const cache128 = new Map();
1090
+ const cache32 = new Map();
1091
+ const cacheSvg = new Map();
1092
+ router$3.get("/icon/128/:filename", async (req, res) => {
1093
+ const filename = req.params.filename;
1094
+ // Check cache first
1095
+ if (cache128.has(filename)) {
1096
+ res.setHeader("Content-Type", "image/png");
1097
+ return await micro.send(res, 200, cache128.get(filename));
1098
+ }
1099
+ const filePath = path.join(ASSET_128, filename);
1100
+ if (fs$1.existsSync(filePath)) {
1101
+ const fileBuffer = await fs.readFile(filePath);
1102
+ cache128.set(filename, fileBuffer);
1103
+ res.setHeader("Content-Type", "image/png");
1104
+ return await micro.send(res, 200, fileBuffer);
1105
+ }
1106
+ return await micro.send(res, 404, "File not found (128)");
1107
+ });
1108
+ router$3.get("/icon/32/:filename", async (req, res) => {
1109
+ const filename = req.params.filename;
1110
+ // Check cache first
1111
+ if (cache32.has(filename)) {
1112
+ res.setHeader("Content-Type", "image/png");
1113
+ return await micro.send(res, 200, cache32.get(filename));
1114
+ }
1115
+ const filePath = path.join(ASSET_32, filename);
1116
+ if (fs$1.existsSync(filePath)) {
1117
+ const fileBuffer = await fs.readFile(filePath);
1118
+ cache32.set(filename, fileBuffer);
1119
+ res.setHeader("Content-Type", "image/png");
1120
+ return await micro.send(res, 200, fileBuffer);
1121
+ }
1122
+ return await micro.send(res, 404, "File not found (32)");
1123
+ });
1124
+ router$3.get("/icon/svg/:filename", async (req, res) => {
1125
+ const filename = req.params.filename;
1126
+ // Check cache first
1127
+ if (cacheSvg.has(filename)) {
1128
+ res.setHeader("Content-Type", "image/svg+xml");
1129
+ return await micro.send(res, 200, cacheSvg.get(filename));
1130
+ }
1131
+ const filePath = path.join(ASSET_SVG, filename);
1132
+ if (fs$1.existsSync(filePath)) {
1133
+ const fileBuffer = await fs.readFile(filePath);
1134
+ cacheSvg.set(filename, fileBuffer);
1135
+ res.setHeader("Content-Type", "image/svg+xml");
1136
+ return await micro.send(res, 200, fileBuffer);
1137
+ }
1138
+ return await micro.send(res, 404, "File not found (svg)");
1139
+ });
1140
+ router$3.get("/icon/:filename", async (req, res) => {
1141
+ const filename = req.params.filename;
1142
+ // Check cache first
1143
+ if (cache32.has(filename)) {
1144
+ res.setHeader("Content-Type", "image/png");
1145
+ return await micro.send(res, 200, cache32.get(filename));
1146
+ }
1147
+ const filePath = path.join(ASSET_32, filename);
1148
+ if (fs$1.existsSync(filePath)) {
1149
+ const fileBuffer = await fs.readFile(filePath);
1150
+ cache32.set(filename, fileBuffer);
1151
+ res.setHeader("Content-Type", "image/png");
1152
+ return await micro.send(res, 200, fileBuffer);
1153
+ }
1154
+ return await micro.send(res, 404, "File not found (root)");
1155
+ });
1156
+
1157
+ const router$2 = Router({
1158
+ params: true,
1159
+ });
1160
+ router$2.post("/api/v1/dict/symbol/list", async (req, res) => {
1161
+ try {
1162
+ const request = await micro.json(req);
1163
+ const { requestId, serviceName } = request;
1164
+ const data = await ioc.symbolMetaService.getSymbolList();
1165
+ const result = {
1166
+ data,
1167
+ status: "ok",
1168
+ error: "",
1169
+ requestId,
1170
+ serviceName,
1171
+ };
1172
+ ioc.loggerService.log("/api/v1/dict/symbol/list ok", {
1173
+ request,
1174
+ result: omit(result, "data"),
1175
+ });
1176
+ return await micro.send(res, 200, result);
1177
+ }
1178
+ catch (error) {
1179
+ ioc.loggerService.log("/api/v1/dict/symbol/list error", {
1180
+ error: functoolsKit.errorData(error),
1181
+ });
1182
+ return await micro.send(res, 200, {
1183
+ status: "error",
1184
+ error: functoolsKit.getErrorMessage(error),
1185
+ });
1186
+ }
1187
+ });
1188
+ router$2.post("/api/v1/dict/symbol/map", async (req, res) => {
1189
+ try {
1190
+ const request = await micro.json(req);
1191
+ const { requestId, serviceName } = request;
1192
+ const data = await ioc.symbolMetaService.getSymbolMap();
1193
+ const result = {
1194
+ data,
1195
+ status: "ok",
1196
+ error: "",
1197
+ requestId,
1198
+ serviceName,
1199
+ };
1200
+ ioc.loggerService.log("/api/v1/dict/symbol/map ok", {
1201
+ request,
1202
+ result: omit(result, "data"),
1203
+ });
1204
+ return await micro.send(res, 200, result);
1205
+ }
1206
+ catch (error) {
1207
+ ioc.loggerService.log("/api/v1/dict/symbol/map error", {
1208
+ error: functoolsKit.errorData(error),
1209
+ });
1210
+ return await micro.send(res, 200, {
1211
+ status: "error",
1212
+ error: functoolsKit.getErrorMessage(error),
1213
+ });
1214
+ }
1215
+ });
1216
+ router$2.post("/api/v1/dict/symbol/one", async (req, res) => {
1217
+ try {
1218
+ const request = await micro.json(req);
1219
+ const { requestId, serviceName, id } = request;
1220
+ const data = await ioc.symbolMetaService.getSymbol(id);
1221
+ const result = {
1222
+ data,
1223
+ status: "ok",
1224
+ error: "",
1225
+ requestId,
1226
+ serviceName,
1227
+ };
1228
+ ioc.loggerService.log("/api/v1/dict/symbol/one ok", {
1229
+ request,
1230
+ result: omit(result, "data"),
1231
+ });
1232
+ return await micro.send(res, 200, result);
1233
+ }
1234
+ catch (error) {
1235
+ ioc.loggerService.log("/api/v1/dict/symbol/one error", {
1236
+ error: functoolsKit.errorData(error),
1237
+ });
1238
+ return await micro.send(res, 200, {
1239
+ status: "error",
1240
+ error: functoolsKit.getErrorMessage(error),
1241
+ });
1242
+ }
1243
+ });
1244
+
1245
+ const require$1 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
1246
+ function getPublicPath() {
1247
+ const modulePath = require$1.resolve('@backtest-kit/ui');
1248
+ const basePath = path.dirname(modulePath);
1249
+ return path.join(basePath, "./modules/frontend/build");
1250
+ }
1251
+
1252
+ const router = Router({
1253
+ params: true,
1254
+ });
1255
+ router.all("/api/v1/health/*", (req, res) => {
1256
+ return router$6(req, res, finalhandler(req, res));
1257
+ });
1258
+ router.all("/api/v1/mock/*", (req, res) => {
1259
+ return router$5(req, res, finalhandler(req, res));
1260
+ });
1261
+ router.all("/api/v1/view/*", (req, res) => {
1262
+ return router$4(req, res, finalhandler(req, res));
1263
+ });
1264
+ router.all("/icon/*", (req, res) => {
1265
+ return router$3(req, res, finalhandler(req, res));
1266
+ });
1267
+ router.all("/api/v1/dict/*", (req, res) => {
1268
+ return router$2(req, res, finalhandler(req, res));
1269
+ });
1270
+ router.get("/*", (req, res) => serveHandler(req, res, {
1271
+ public: CC_ENABLE_MOCK
1272
+ ? CC_WWWROOT_PATH || "./build/modules/frontend/build"
1273
+ : CC_WWWROOT_PATH || getPublicPath(),
1274
+ }));
1275
+ var router$1 = micro.serve(async (req, res) => {
1276
+ res.setHeader("Access-Control-Allow-Origin", "*");
1277
+ res.setHeader("Access-Control-Allow-Headers", "*");
1278
+ res.setHeader("Access-Control-Allow-Credentials", "true");
1279
+ res.setHeader("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
1280
+ return router(req, res, finalhandler(req, res));
1281
+ });
1282
+
1283
+ const METHOD_NAME_SERVE = "serve.serve";
1284
+ const METHOD_NAME_GET_ROUTER = "serve.getRouter";
1285
+ const MAX_CONNECTIONS = 1000;
1286
+ const SOCKET_TIMEOUT = 60 * 10 * 1000;
1287
+ const serveInternal = functoolsKit.singleshot((host = CC_WWWROOT_HOST, port = CC_WWWROOT_PORT) => {
1288
+ const server = new http.Server(router$1);
1289
+ server.listen(port, host).addListener("listening", () => {
1290
+ console.log(`Listening on http://${host}:${port}`);
1291
+ });
1292
+ server.maxConnections = MAX_CONNECTIONS;
1293
+ server.setTimeout(SOCKET_TIMEOUT);
1294
+ return () => {
1295
+ server.close();
1296
+ serveInternal.clear();
1297
+ };
1298
+ });
1299
+ function serve(host, port) {
1300
+ ioc.loggerService.log(METHOD_NAME_SERVE, {
1301
+ host,
1302
+ port,
1303
+ });
1304
+ return serveInternal(host, port);
1305
+ }
1306
+ function getRouter() {
1307
+ ioc.loggerService.log(METHOD_NAME_GET_ROUTER);
1308
+ return router$1;
1309
+ }
1310
+
1311
+ const setLogger = (logger) => {
1312
+ ioc.loggerService.setLogger(logger);
1313
+ };
1314
+
1315
+ exports.getModulesPath = getModulesPath;
1316
+ exports.getPublicPath = getPublicPath;
1317
+ exports.getRouter = getRouter;
1318
+ exports.lib = ioc;
1319
+ exports.serve = serve;
1320
+ exports.setLogger = setLogger;