init:创建后端项目框架,确保环境的基本运行
This commit is contained in:
39
.gitignore
vendored
Normal file
39
.gitignore
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# 依赖
|
||||
node_modules/
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
|
||||
# 构建输出
|
||||
dist/
|
||||
build/
|
||||
*.tsbuildinfo
|
||||
|
||||
# 环境变量
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# 日志
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# 操作系统
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# 测试覆盖率
|
||||
coverage/
|
||||
.nyc_output/
|
||||
|
||||
# 临时文件
|
||||
*.tmp
|
||||
.cache/
|
||||
72
README.md
Normal file
72
README.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# Pixel Game Server
|
||||
|
||||
一个基于 NestJS 的 2D 像素风游戏后端服务
|
||||
|
||||
## 技术栈
|
||||
|
||||
- **NestJS** - 渐进式 Node.js 框架
|
||||
- **TypeScript** - 类型安全
|
||||
- **WebSocket** - 实时通信支持
|
||||
|
||||
## 前置要求
|
||||
|
||||
如果还没有安装 Yarn,请先安装:
|
||||
|
||||
```bash
|
||||
npm install -g yarn
|
||||
```
|
||||
|
||||
## 安装依赖
|
||||
|
||||
```bash
|
||||
yarn install
|
||||
```
|
||||
|
||||
## 开发
|
||||
|
||||
启动开发服务器(支持热重载):
|
||||
|
||||
```bash
|
||||
yarn dev
|
||||
```
|
||||
|
||||
服务器将运行在 `http://localhost:3000`
|
||||
|
||||
## 构建
|
||||
|
||||
```bash
|
||||
yarn build
|
||||
```
|
||||
|
||||
## 生产环境运行
|
||||
|
||||
```bash
|
||||
yarn start:prod
|
||||
```
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
src/
|
||||
├── api/ # API 接口层(控制器、网关)
|
||||
├── config/ # 配置文件
|
||||
├── data/ # 数据访问层(数据库、缓存)
|
||||
├── model/ # 数据模型、实体、DTO
|
||||
├── service/ # 业务逻辑层
|
||||
├── utils/ # 工具函数
|
||||
├── main.ts # 应用入口
|
||||
├── app.module.ts # 根模块
|
||||
├── app.controller.ts # 根控制器
|
||||
└── app.service.ts # 根服务
|
||||
test/
|
||||
├── api/ # API 测试
|
||||
└── service/ # 服务测试
|
||||
```
|
||||
|
||||
## 下一步
|
||||
|
||||
- 在 `src/api/` 目录下创建游戏相关的控制器和网关
|
||||
- 在 `src/model/` 目录下定义游戏数据模型
|
||||
- 在 `src/service/` 目录下实现游戏业务逻辑
|
||||
- 使用 NestJS CLI 快速生成模块:`nest g module game`
|
||||
- 添加 WebSocket 网关实现实时游戏逻辑
|
||||
8
nest-cli.json
Normal file
8
nest-cli.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
31
package.json
Normal file
31
package.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "pixel-game-server",
|
||||
"version": "1.0.0",
|
||||
"description": "A 2D pixel art game server built with NestJS",
|
||||
"main": "dist/main.js",
|
||||
"scripts": {
|
||||
"dev": "nest start --watch",
|
||||
"build": "nest build",
|
||||
"start": "node dist/main.js",
|
||||
"start:prod": "node dist/main.js"
|
||||
},
|
||||
"keywords": ["game", "pixel", "2d", "server", "nestjs"],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@nestjs/websockets": "^10.0.0",
|
||||
"@nestjs/platform-socket.io": "^10.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^10.0.0",
|
||||
"@nestjs/schematics": "^10.0.0",
|
||||
"@types/node": "^20.0.0",
|
||||
"ts-node": "^10.9.0",
|
||||
"typescript": "^5.3.0"
|
||||
}
|
||||
}
|
||||
0
src/api/.gitkeep
Normal file
0
src/api/.gitkeep
Normal file
12
src/app.controller.ts
Normal file
12
src/app.controller.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getStatus(): string {
|
||||
return this.appService.getStatus();
|
||||
}
|
||||
}
|
||||
10
src/app.module.ts
Normal file
10
src/app.module.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
8
src/app.service.ts
Normal file
8
src/app.service.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getStatus(): string {
|
||||
return 'Pixel Game Server is running!';
|
||||
}
|
||||
}
|
||||
0
src/config/.gitkeep
Normal file
0
src/config/.gitkeep
Normal file
0
src/data/.gitkeep
Normal file
0
src/data/.gitkeep
Normal file
10
src/main.ts
Normal file
10
src/main.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(3000);
|
||||
console.log('Pixel Game Server is running on http://localhost:3000');
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
0
src/model/.gitkeep
Normal file
0
src/model/.gitkeep
Normal file
0
src/service/.gitkeep
Normal file
0
src/service/.gitkeep
Normal file
0
src/utils/.gitkeep
Normal file
0
src/utils/.gitkeep
Normal file
0
test/api/.gitkeep
Normal file
0
test/api/.gitkeep
Normal file
0
test/service/.gitkeep
Normal file
0
test/service/.gitkeep
Normal file
24
tsconfig.json
Normal file
24
tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "CommonJS",
|
||||
"lib": ["ES2020"],
|
||||
"moduleResolution": "node",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"strictNullChecks": false
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user