mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-12-05 10:31:56 +00:00
feat:初始化时自动生成.env
This commit is contained in:
parent
3200c39a7d
commit
258de609df
@ -1,34 +0,0 @@
|
||||
// @ts-check
|
||||
import eslint from '@eslint/js';
|
||||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
||||
import globals from 'globals';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default tseslint.config(
|
||||
{
|
||||
ignores: ['eslint.config.mjs'],
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
eslintPluginPrettierRecommended,
|
||||
{
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.jest,
|
||||
},
|
||||
sourceType: 'commonjs',
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-floating-promises': 'warn',
|
||||
'@typescript-eslint/no-unsafe-argument': 'warn'
|
||||
},
|
||||
},
|
||||
);
|
||||
25
src/main.ts
25
src/main.ts
@ -6,9 +6,24 @@ import { ResponseInterceptor } from './common/interceptors/response.interceptor'
|
||||
import { AllExceptionsFilter } from './common/filters/all-exception.filter';
|
||||
import { SystemService } from './core/system/system.service';
|
||||
import { WsAdapter } from '@nestjs/platform-ws';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
async function bootstrap() {
|
||||
Logger.log('晶灵核心初始化..');
|
||||
Logger.log('晶灵核心初始化..', '', 'Core');
|
||||
const envPath = path.join(__dirname, '../.env');
|
||||
const envExamplePath = path.join(__dirname, '../.envExample');
|
||||
if (!fs.existsSync(envPath)) {
|
||||
if (fs.existsSync(envExamplePath)) {
|
||||
fs.copyFileSync(envExamplePath, envPath);
|
||||
Logger.warn(`.env 文件已自动生成,请修改配置后重启核心..`, '', 'ENV');
|
||||
process.exit(1);
|
||||
} else {
|
||||
Logger.error('配置模块初始化出错,请重新拉取应用!', '', 'ENV');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.setGlobalPrefix('api', {
|
||||
exclude: [
|
||||
@ -18,12 +33,13 @@ async function bootstrap() {
|
||||
{ path: 'public/(.*)', method: RequestMethod.ALL },
|
||||
],
|
||||
});
|
||||
|
||||
app.useGlobalInterceptors(new ResponseInterceptor());
|
||||
app.useGlobalFilters(new AllExceptionsFilter());
|
||||
const systemService = app.get(SystemService);
|
||||
const restartDuration = systemService.checkRestartTime();
|
||||
if (restartDuration) {
|
||||
new Logger('System').warn(`重启完成!耗时 ${restartDuration} 秒`);
|
||||
Logger.warn(`重启完成!耗时 ${restartDuration} 秒`, '', 'System');
|
||||
}
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('晶灵核心')
|
||||
@ -38,7 +54,8 @@ async function bootstrap() {
|
||||
Logger.error(`自动更新失败: ${err?.message}`, '', 'System');
|
||||
});
|
||||
}
|
||||
|
||||
bootstrap().then(() => {
|
||||
Logger.log(`API服务已启动:http://localhost:6868/api`);
|
||||
Logger.log(`API文档: http://localhost:6868/docs`);
|
||||
Logger.log(`API服务已启动:http://localhost:6868/api`, '', 'Core');
|
||||
Logger.log(`API文档: http://localhost:6868/docs`, '', 'Core');
|
||||
});
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { Controller, Post, Inject, UseGuards, Param } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiBody, ApiProperty } from '@nestjs/swagger';
|
||||
import { SystemWebService } from './systemWeb.service';
|
||||
import { ToolsService } from '../../core/tools/tools.service';
|
||||
import { TokenAuthGuard } from '../../core/tools/token-auth.guard';
|
||||
|
||||
class WebServerDto {
|
||||
@ -18,8 +17,6 @@ export class SystemWebController {
|
||||
constructor(
|
||||
@Inject(SystemWebService)
|
||||
private readonly systemService: SystemWebService,
|
||||
@Inject(ToolsService)
|
||||
private readonly toolService: ToolsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { SystemWebController } from './systemWeb.controller';
|
||||
import { SystemWebService } from './systemWeb.service';
|
||||
import { ToolsModule } from '../../core/tools/tools.module';
|
||||
import { PathModule } from '../../core/path/path.module';
|
||||
import { SystemModule } from '../../core/system/system.module';
|
||||
import { ToolsModule } from '../../core/tools/tools.module';
|
||||
|
||||
@Module({
|
||||
imports: [ToolsModule, SystemModule, PathModule],
|
||||
imports: [SystemModule, PathModule, ToolsModule],
|
||||
controllers: [SystemWebController],
|
||||
providers: [SystemWebService],
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user