feat: Complete NestJS backend scaffold — 22 modules, 39 entities, WebSocket gateway
All checks were successful
Test Asgard Runner / test (push) Successful in 3s
All checks were successful
Test Asgard Runner / test (push) Successful in 3s
Full backend rewrite from Rust/Axum to NestJS/TypeScript. - 22 feature modules (auth, servers, wipes, maps, plugins, players, console, chat, team, notifications, settings, schedules, analytics, alerts, status, store, webstore, admin, setup, migration, users, licenses) - 39 TypeORM entities matching PostgreSQL schema (12 migrations) - Common infrastructure: JWT/RBAC guards, decorators, exception filter - NATS service with pub/sub/request-reply - Socket.IO WebSocket gateway with NATS bridge - Docker: NestJS Dockerfile + updated docker-compose.yml - Zero compile errors (npx tsc --noEmit clean) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
12
backend-nest/src/modules/servers/dto/send-command.dto.ts
Normal file
12
backend-nest/src/modules/servers/dto/send-command.dto.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { IsString, IsNotEmpty } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class SendCommandDto {
|
||||
@ApiProperty({
|
||||
example: 'say "Hello, players!"',
|
||||
description: 'Console command to execute on the server',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
command: string;
|
||||
}
|
||||
56
backend-nest/src/modules/servers/dto/update-config.dto.ts
Normal file
56
backend-nest/src/modules/servers/dto/update-config.dto.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { IsOptional, IsString, IsInt, IsBoolean } from 'class-validator';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
|
||||
export class UpdateServerConfigDto {
|
||||
@ApiPropertyOptional({ example: 'My Rust Server', description: 'Server name' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
server_name?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 100, description: 'Maximum players' })
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
max_players?: number;
|
||||
|
||||
@ApiPropertyOptional({ example: 4000, description: 'World size' })
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
world_size?: number;
|
||||
|
||||
@ApiPropertyOptional({ example: 123456, description: 'Current world seed' })
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
current_seed?: number;
|
||||
|
||||
@ApiPropertyOptional({ example: true, description: 'Enable auto-restart' })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
auto_restart_enabled?: boolean;
|
||||
|
||||
@ApiPropertyOptional({ example: '0 4 * * *', description: 'Auto-restart cron schedule' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
auto_restart_cron?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: true, description: 'Enable crash recovery' })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
crash_recovery_enabled?: boolean;
|
||||
|
||||
@ApiPropertyOptional({ example: true, description: 'Eligible for force wipes' })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
force_wipe_eligible?: boolean;
|
||||
|
||||
@ApiPropertyOptional({ example: true, description: 'Auto-update on force wipe' })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
auto_update_on_force_wipe?: boolean;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
example: { 'server.pve': 'true', 'server.radiation': 'false' },
|
||||
description: 'Server config overrides (key-value pairs)',
|
||||
})
|
||||
@IsOptional()
|
||||
config_overrides?: Record<string, string>;
|
||||
}
|
||||
65
backend-nest/src/modules/servers/servers.controller.ts
Normal file
65
backend-nest/src/modules/servers/servers.controller.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { Controller, Get, Put, Post, Body, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import { ServersService } from './servers.service';
|
||||
import { UpdateServerConfigDto } from './dto/update-config.dto';
|
||||
import { SendCommandDto } from './dto/send-command.dto';
|
||||
import { CurrentTenant } from '../../common/decorators/current-tenant.decorator';
|
||||
import { RequirePermission } from '../../common/decorators/require-permission.decorator';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { PermissionsGuard } from '../../common/guards/permissions.guard';
|
||||
|
||||
@ApiTags('Servers')
|
||||
@ApiBearerAuth()
|
||||
@Controller('servers')
|
||||
@UseGuards(JwtAuthGuard, PermissionsGuard)
|
||||
export class ServersController {
|
||||
constructor(private readonly serversService: ServersService) {}
|
||||
|
||||
@Get()
|
||||
@RequirePermission('server.view')
|
||||
@ApiOperation({ summary: 'Get server connection and config' })
|
||||
async getServer(@CurrentTenant() licenseId: string) {
|
||||
return await this.serversService.getServer(licenseId);
|
||||
}
|
||||
|
||||
@Put('config')
|
||||
@RequirePermission('server.manage')
|
||||
@ApiOperation({ summary: 'Update server configuration' })
|
||||
async updateConfig(
|
||||
@CurrentTenant() licenseId: string,
|
||||
@Body() dto: UpdateServerConfigDto,
|
||||
) {
|
||||
return await this.serversService.updateConfig(licenseId, dto);
|
||||
}
|
||||
|
||||
@Post('command')
|
||||
@RequirePermission('server.console')
|
||||
@ApiOperation({ summary: 'Send console command to server' })
|
||||
async sendCommand(
|
||||
@CurrentTenant() licenseId: string,
|
||||
@Body() dto: SendCommandDto,
|
||||
) {
|
||||
return await this.serversService.sendCommand(licenseId, dto.command);
|
||||
}
|
||||
|
||||
@Post('start')
|
||||
@RequirePermission('server.manage')
|
||||
@ApiOperation({ summary: 'Start the server' })
|
||||
async startServer(@CurrentTenant() licenseId: string) {
|
||||
return await this.serversService.startServer(licenseId);
|
||||
}
|
||||
|
||||
@Post('stop')
|
||||
@RequirePermission('server.manage')
|
||||
@ApiOperation({ summary: 'Stop the server' })
|
||||
async stopServer(@CurrentTenant() licenseId: string) {
|
||||
return await this.serversService.stopServer(licenseId);
|
||||
}
|
||||
|
||||
@Post('restart')
|
||||
@RequirePermission('server.manage')
|
||||
@ApiOperation({ summary: 'Restart the server' })
|
||||
async restartServer(@CurrentTenant() licenseId: string) {
|
||||
return await this.serversService.restartServer(licenseId);
|
||||
}
|
||||
}
|
||||
15
backend-nest/src/modules/servers/servers.module.ts
Normal file
15
backend-nest/src/modules/servers/servers.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ServersController } from './servers.controller';
|
||||
import { ServersService } from './servers.service';
|
||||
import { ServerConnection } from '../../entities/server-connection.entity';
|
||||
import { ServerConfig } from '../../entities/server-config.entity';
|
||||
import { NatsService } from '../../services/nats.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([ServerConnection, ServerConfig])],
|
||||
controllers: [ServersController],
|
||||
providers: [ServersService, NatsService],
|
||||
exports: [ServersService],
|
||||
})
|
||||
export class ServersModule {}
|
||||
88
backend-nest/src/modules/servers/servers.service.ts
Normal file
88
backend-nest/src/modules/servers/servers.service.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ServerConnection } from '../../entities/server-connection.entity';
|
||||
import { ServerConfig } from '../../entities/server-config.entity';
|
||||
import { NatsService } from '../../services/nats.service';
|
||||
import { UpdateServerConfigDto } from './dto/update-config.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ServersService {
|
||||
constructor(
|
||||
@InjectRepository(ServerConnection)
|
||||
private readonly connectionRepo: Repository<ServerConnection>,
|
||||
@InjectRepository(ServerConfig)
|
||||
private readonly configRepo: Repository<ServerConfig>,
|
||||
private readonly natsService: NatsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get server connection and config for a license
|
||||
*/
|
||||
async getServer(licenseId: string) {
|
||||
const connection = await this.connectionRepo.findOne({
|
||||
where: { license_id: licenseId },
|
||||
});
|
||||
|
||||
const config = await this.configRepo.findOne({
|
||||
where: { license_id: licenseId },
|
||||
});
|
||||
|
||||
if (!connection || !config) {
|
||||
throw new NotFoundException('Server not found for this license');
|
||||
}
|
||||
|
||||
return { connection, config };
|
||||
}
|
||||
|
||||
/**
|
||||
* Update server configuration
|
||||
*/
|
||||
async updateConfig(licenseId: string, dto: UpdateServerConfigDto) {
|
||||
const config = await this.configRepo.findOne({
|
||||
where: { license_id: licenseId },
|
||||
});
|
||||
|
||||
if (!config) {
|
||||
throw new NotFoundException('Server config not found');
|
||||
}
|
||||
|
||||
// Apply updates
|
||||
Object.assign(config, dto);
|
||||
config.updated_at = new Date();
|
||||
|
||||
return await this.configRepo.save(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a console command to the server via NATS
|
||||
*/
|
||||
async sendCommand(licenseId: string, command: string) {
|
||||
await this.natsService.sendServerCommand(licenseId, 'command', { command });
|
||||
return { output: 'Command sent' };
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the server via NATS
|
||||
*/
|
||||
async startServer(licenseId: string) {
|
||||
await this.natsService.sendServerCommand(licenseId, 'start');
|
||||
return { message: 'Start command sent' };
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the server via NATS
|
||||
*/
|
||||
async stopServer(licenseId: string) {
|
||||
await this.natsService.sendServerCommand(licenseId, 'stop');
|
||||
return { message: 'Stop command sent' };
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart the server via NATS
|
||||
*/
|
||||
async restartServer(licenseId: string) {
|
||||
await this.natsService.sendServerCommand(licenseId, 'restart');
|
||||
return { message: 'Restart command sent' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user