|
|
@ -9,7 +9,7 @@ import dotenv from 'dotenv'; |
|
|
|
import { IoAdapter } from '@nestjs/platform-socket.io'; |
|
|
|
import { IoAdapter } from '@nestjs/platform-socket.io'; |
|
|
|
import requestIp from 'request-ip'; |
|
|
|
import requestIp from 'request-ip'; |
|
|
|
import cookieParser from 'cookie-parser'; |
|
|
|
import cookieParser from 'cookie-parser'; |
|
|
|
import { Logger } from '@nestjs/common'; |
|
|
|
import type { INestApplication } from '@nestjs/common'; |
|
|
|
import type { MetaService } from '~/meta/meta.service'; |
|
|
|
import type { MetaService } from '~/meta/meta.service'; |
|
|
|
import type { IEventEmitter } from '~/modules/event-emitter/event-emitter.interface'; |
|
|
|
import type { IEventEmitter } from '~/modules/event-emitter/event-emitter.interface'; |
|
|
|
import type { Express } from 'express'; |
|
|
|
import type { Express } from 'express'; |
|
|
@ -21,17 +21,16 @@ import { isEE } from '~/utils'; |
|
|
|
dotenv.config(); |
|
|
|
dotenv.config(); |
|
|
|
|
|
|
|
|
|
|
|
export default class Noco { |
|
|
|
export default class Noco { |
|
|
|
private static _this: Noco; |
|
|
|
protected static _this: Noco; |
|
|
|
private static ee: boolean; |
|
|
|
protected static ee: boolean; |
|
|
|
public static readonly env: string = '_noco'; |
|
|
|
public static readonly env: string = '_noco'; |
|
|
|
private static _httpServer: http.Server; |
|
|
|
protected static _httpServer: http.Server; |
|
|
|
private static _server: Express; |
|
|
|
protected static _server: Express; |
|
|
|
private static logger = new Logger(Noco.name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static get dashboardUrl(): string { |
|
|
|
public static get dashboardUrl(): string { |
|
|
|
const siteUrl = `http://localhost:${process.env.PORT || 8080}`; |
|
|
|
const siteUrl = `http://localhost:${process.env.PORT || 8080}`; |
|
|
|
|
|
|
|
|
|
|
|
return `${siteUrl}${Noco._this?.config?.dashboardPath}`; |
|
|
|
return `${siteUrl}${this._this?.config?.dashboardPath}`; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static config: any; |
|
|
|
public static config: any; |
|
|
@ -43,8 +42,8 @@ export default class Noco { |
|
|
|
public readonly metaMgrv2: any; |
|
|
|
public readonly metaMgrv2: any; |
|
|
|
public env: string; |
|
|
|
public env: string; |
|
|
|
|
|
|
|
|
|
|
|
private config: any; |
|
|
|
protected config: any; |
|
|
|
private requestContext: any; |
|
|
|
protected requestContext: any; |
|
|
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
process.env.PORT = process.env.PORT || '8080'; |
|
|
|
process.env.PORT = process.env.PORT || '8080'; |
|
|
@ -82,22 +81,26 @@ export default class Noco { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static getConfig(): any { |
|
|
|
public static getConfig(): any { |
|
|
|
return Noco.config; |
|
|
|
return this.config; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static isEE(): boolean { |
|
|
|
public static isEE(): boolean { |
|
|
|
return Noco.ee || process.env.NC_CLOUD === 'true'; |
|
|
|
return this.ee || process.env.NC_CLOUD === 'true'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static async loadEEState(): Promise<boolean> { |
|
|
|
public static async loadEEState(): Promise<boolean> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return (Noco.ee = isEE); |
|
|
|
return (this.ee = isEE); |
|
|
|
} catch {} |
|
|
|
} catch {} |
|
|
|
return (Noco.ee = false); |
|
|
|
return (this.ee = false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static async init(param: any, httpServer: http.Server, server: Express) { |
|
|
|
static async init(param: any, httpServer: http.Server, server: Express) { |
|
|
|
const nestApp = await NestFactory.create(AppModule); |
|
|
|
const nestApp = await NestFactory.create(AppModule, { |
|
|
|
|
|
|
|
bufferLogs: true, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.initCustomLogger(nestApp); |
|
|
|
|
|
|
|
nestApp.flushLogs(); |
|
|
|
|
|
|
|
|
|
|
|
if (process.env.NC_WORKER_CONTAINER === 'true') { |
|
|
|
if (process.env.NC_WORKER_CONTAINER === 'true') { |
|
|
|
if (!process.env.NC_REDIS_URL) { |
|
|
|
if (!process.env.NC_REDIS_URL) { |
|
|
@ -136,23 +139,23 @@ export default class Noco { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static get httpServer(): http.Server { |
|
|
|
public static get httpServer(): http.Server { |
|
|
|
return Noco._httpServer; |
|
|
|
return this._httpServer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static get server(): Express { |
|
|
|
public static get server(): Express { |
|
|
|
return Noco._server; |
|
|
|
return this._server; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static async initJwt(): Promise<any> { |
|
|
|
public static async initJwt(): Promise<any> { |
|
|
|
if (this.config?.auth?.jwt) { |
|
|
|
if (this.config?.auth?.jwt) { |
|
|
|
if (!this.config.auth.jwt.secret) { |
|
|
|
if (!this.config.auth.jwt.secret) { |
|
|
|
let secret = ( |
|
|
|
let secret = ( |
|
|
|
await Noco._ncMeta.metaGet('', '', MetaTable.STORE, { |
|
|
|
await this._ncMeta.metaGet('', '', MetaTable.STORE, { |
|
|
|
key: 'nc_auth_jwt_secret', |
|
|
|
key: 'nc_auth_jwt_secret', |
|
|
|
}) |
|
|
|
}) |
|
|
|
)?.value; |
|
|
|
)?.value; |
|
|
|
if (!secret) { |
|
|
|
if (!secret) { |
|
|
|
await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, { |
|
|
|
await this._ncMeta.metaInsert('', '', MetaTable.STORE, { |
|
|
|
key: 'nc_auth_jwt_secret', |
|
|
|
key: 'nc_auth_jwt_secret', |
|
|
|
value: (secret = uuidv4()), |
|
|
|
value: (secret = uuidv4()), |
|
|
|
}); |
|
|
|
}); |
|
|
@ -167,16 +170,20 @@ export default class Noco { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
let serverId = ( |
|
|
|
let serverId = ( |
|
|
|
await Noco._ncMeta.metaGet('', '', MetaTable.STORE, { |
|
|
|
await this._ncMeta.metaGet('', '', MetaTable.STORE, { |
|
|
|
key: 'nc_server_id', |
|
|
|
key: 'nc_server_id', |
|
|
|
}) |
|
|
|
}) |
|
|
|
)?.value; |
|
|
|
)?.value; |
|
|
|
if (!serverId) { |
|
|
|
if (!serverId) { |
|
|
|
await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, { |
|
|
|
await this._ncMeta.metaInsert('', '', MetaTable.STORE, { |
|
|
|
key: 'nc_server_id', |
|
|
|
key: 'nc_server_id', |
|
|
|
value: (serverId = T.id), |
|
|
|
value: (serverId = T.id), |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
process.env.NC_SERVER_UUID = serverId; |
|
|
|
process.env.NC_SERVER_UUID = serverId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected static initCustomLogger(_nestApp: INestApplication<any>) { |
|
|
|
|
|
|
|
// setup custom logger for nestjs if needed
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|