Skip to content

Commit 8bdda37

Browse files
committed
feat: enhance startup message with XRay service information
- Updated getStartMessage to include XRay version, path, and system info. - Refactored XrayController to ensure proper guard usage. - Added getXrayInfo method in XrayService to retrieve XRay details.
1 parent 2471cd5 commit 8bdda37

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

src/common/utils/get-start-message.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
import { getBorderCharacters, table } from 'table';
22
import { readPackageJSON } from 'pkg-types';
33

4-
export async function getStartMessage(appPort: number, internalPort: number) {
4+
import { INestApplication } from '@nestjs/common';
5+
6+
import { XrayService } from '../../modules/xray-core/xray.service';
7+
8+
export async function getStartMessage(
9+
appPort: number,
10+
internalPort: number,
11+
app: INestApplication,
12+
) {
513
const pkg = await readPackageJSON();
614

15+
const xrayService = app.get(XrayService);
16+
17+
const xrayInfo = await xrayService.getXrayInfo();
18+
719
return table(
820
[
921
['Docs → https://remna.st\nCommunity → https://t.me/remnawave'],
1022
[`API Port: ${appPort}\nInternal Port: ${internalPort}`],
23+
[`XRay Core: v${xrayInfo.version || 'N/A'}\nXRay Path: ${xrayInfo.path}`],
24+
[
25+
`SI: ${xrayInfo.systemInfo?.cpuCores}C, ${xrayInfo.systemInfo?.cpuModel}, ${xrayInfo.systemInfo?.memoryTotal}`,
26+
],
1127
],
1228
{
1329
header: {

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ async function bootstrap(): Promise<void> {
9696
(await getStartMessage(
9797
Number(config.getOrThrow<string>('APP_PORT')),
9898
XRAY_INTERNAL_API_PORT,
99+
app,
99100
)) +
100101
'\n',
101102
);

src/modules/xray-core/xray.controller.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
import {
2-
Body,
3-
Controller,
4-
Get,
5-
Ip,
6-
Logger,
7-
Post,
8-
Req,
9-
UseFilters,
10-
UseGuards,
11-
} from '@nestjs/common';
1+
import { Body, Controller, Get, Ip, Logger, Post, UseFilters, UseGuards } from '@nestjs/common';
122

133
import { HttpExceptionFilter } from '@common/exception/httpException.filter';
144
import { JwtDefaultGuard } from '@common/guards/jwt-guards/def-jwt-guard';
@@ -24,8 +14,8 @@ import {
2414
} from './dtos/';
2515
import { XrayService } from './xray.service';
2616

27-
@UseGuards(JwtDefaultGuard)
2817
@UseFilters(HttpExceptionFilter)
18+
@UseGuards(JwtDefaultGuard)
2919
@Controller(XRAY_CONTROLLER)
3020
export class XrayController {
3121
private readonly logger = new Logger(XrayController.name);
@@ -38,10 +28,7 @@ export class XrayController {
3828
public async startXray(
3929
@Body() body: StartXrayRequestDto,
4030
@Ip() ip: string,
41-
@Req() request: Request,
4231
): Promise<StartXrayResponseDto> {
43-
this.logger.log(`Controller: ${JSON.stringify(request.headers)}`);
44-
4532
const response = await this.xrayService.startXray(body, ip);
4633
const data = errorHandler(response);
4734

src/modules/xray-core/xray.service.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export class XrayService implements OnApplicationBootstrap, OnModuleInit {
5555
async onApplicationBootstrap() {
5656
try {
5757
this.systemStats = await getSystemStats();
58-
this.logger.log(`${JSON.stringify(this.systemStats)}`);
5958
} catch (error) {
6059
this.logger.error(`Failed to get node hardware info: ${error}`);
6160
}
@@ -343,6 +342,25 @@ export class XrayService implements OnApplicationBootstrap, OnModuleInit {
343342
return version;
344343
}
345344

345+
public async getXrayInfo(): Promise<{
346+
version: string | null;
347+
path: string;
348+
systemInfo: ISystemStats | null;
349+
}> {
350+
const output = await execa(this.xrayPath, ['version']);
351+
const version = semver.valid(semver.coerce(output.stdout));
352+
353+
if (version) {
354+
this.xrayVersion = version;
355+
}
356+
357+
return {
358+
version: version,
359+
path: this.xrayPath,
360+
systemInfo: this.systemStats,
361+
};
362+
}
363+
346364
private async getXrayInternalStatus(): Promise<boolean> {
347365
const maxRetries = 8;
348366
const delay = 2000;

0 commit comments

Comments
 (0)