2024-10-26 16:36:57 +08:00
|
|
|
import { App, Autoload, Config, Init, Inject, Scope, ScopeEnum } from '@midwayjs/core';
|
2024-11-04 16:39:02 +08:00
|
|
|
import { getPlusInfo, isPlus } from '@certd/plus-core';
|
2024-12-23 13:27:04 +08:00
|
|
|
import { isDev, logger } from '@certd/basic';
|
2024-11-04 16:39:02 +08:00
|
|
|
|
2024-10-14 10:57:12 +08:00
|
|
|
import { SysInstallInfo, SysSettingsService } from '@certd/lib-server';
|
|
|
|
|
import { getVersion } from '../../utils/version.js';
|
2024-10-14 11:41:34 +08:00
|
|
|
import dayjs from 'dayjs';
|
2024-10-26 16:36:57 +08:00
|
|
|
import { Application } from '@midwayjs/koa';
|
2024-10-26 18:01:06 +08:00
|
|
|
import { httpsServer, HttpsServerOptions } from './https/server.js';
|
2024-10-14 10:57:12 +08:00
|
|
|
|
|
|
|
|
@Autoload()
|
2024-12-23 00:24:31 +08:00
|
|
|
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
2024-10-14 10:57:12 +08:00
|
|
|
export class AutoZPrint {
|
|
|
|
|
@Inject()
|
|
|
|
|
sysSettingsService: SysSettingsService;
|
|
|
|
|
|
2024-10-26 16:36:57 +08:00
|
|
|
@App()
|
|
|
|
|
app: Application;
|
|
|
|
|
|
|
|
|
|
@Config('https')
|
|
|
|
|
httpsConfig: HttpsServerOptions;
|
2025-10-11 16:59:28 +08:00
|
|
|
@Config('koa')
|
|
|
|
|
koaConfig: any;
|
2024-10-26 16:36:57 +08:00
|
|
|
|
2024-10-14 10:57:12 +08:00
|
|
|
@Init()
|
|
|
|
|
async init() {
|
2024-10-26 16:36:57 +08:00
|
|
|
//监听https
|
|
|
|
|
this.startHttpsServer();
|
2025-12-12 23:39:09 +08:00
|
|
|
logger.info("ENV:", process.env.NODE_ENV);
|
2024-12-23 23:33:13 +08:00
|
|
|
if (isDev()) {
|
|
|
|
|
this.startHeapLog();
|
|
|
|
|
}
|
2024-10-14 10:57:12 +08:00
|
|
|
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
|
|
|
|
logger.info('=========================================');
|
|
|
|
|
logger.info('当前站点ID:', installInfo.siteId);
|
|
|
|
|
const version = await getVersion();
|
|
|
|
|
logger.info(`当前版本:${version}`);
|
2024-10-14 11:41:34 +08:00
|
|
|
const plusInfo = getPlusInfo();
|
|
|
|
|
if (isPlus()) {
|
|
|
|
|
logger.info(`授权信息:${plusInfo.vipType},${dayjs(plusInfo.expireTime).format('YYYY-MM-DD')}`);
|
|
|
|
|
}
|
2024-10-14 11:52:37 +08:00
|
|
|
logger.info('Certd已启动');
|
2024-10-14 10:57:12 +08:00
|
|
|
logger.info('=========================================');
|
2024-12-23 13:27:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startHeapLog() {
|
|
|
|
|
function format(bytes: any) {
|
|
|
|
|
return (bytes / 1024 / 1024).toFixed(2) + ' MB';
|
|
|
|
|
}
|
|
|
|
|
setInterval(() => {
|
2025-01-02 17:48:54 +08:00
|
|
|
const mu = process.memoryUsage();
|
|
|
|
|
logger.info(`rss:${format(mu.rss)},heapUsed: ${format(mu.heapUsed)},heapTotal: ${format(mu.heapTotal)},external: ${format(mu.external)}`);
|
2025-12-12 23:39:09 +08:00
|
|
|
}, 20000);
|
2024-10-14 10:57:12 +08:00
|
|
|
}
|
2024-10-26 16:36:57 +08:00
|
|
|
|
2024-12-23 23:33:13 +08:00
|
|
|
startHttpsServer() {
|
2024-10-26 16:36:57 +08:00
|
|
|
if (!this.httpsConfig.enabled) {
|
|
|
|
|
logger.info('Https server is not enabled');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-10-26 18:01:06 +08:00
|
|
|
httpsServer.start({
|
2024-10-26 16:36:57 +08:00
|
|
|
...this.httpsConfig,
|
|
|
|
|
app: this.app,
|
2025-10-11 16:59:28 +08:00
|
|
|
hostname: this.httpsConfig.hostname || this.koaConfig.hostname,
|
2024-10-26 16:36:57 +08:00
|
|
|
});
|
|
|
|
|
}
|
2024-10-14 10:57:12 +08:00
|
|
|
}
|