This commit is contained in:
longdayi 2025-02-23 19:37:11 +08:00
parent 62bd20c906
commit 2d8ef17f36
8 changed files with 116 additions and 10 deletions

View File

@ -4,19 +4,27 @@ import { TrpcRouter } from './trpc/trpc.router';
import { WebSocketService } from './socket/websocket.service'; import { WebSocketService } from './socket/websocket.service';
async function bootstrap() { async function bootstrap() {
// 创建NestJS应用实例
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
// 启用 CORS 并允许所有来源 // 启用 CORS 并允许所有来源
app.enableCors({ app.enableCors({
origin: '*', origin: '*',
}); });
// 获取WebSocket服务实例并初始化
const wsService = app.get(WebSocketService); const wsService = app.get(WebSocketService);
await wsService.initialize(app.getHttpServer()); await wsService.initialize(app.getHttpServer());
// 获取tRPC路由实例并应用中间件
const trpc = app.get(TrpcRouter); const trpc = app.get(TrpcRouter);
trpc.applyMiddleware(app); trpc.applyMiddleware(app);
// 设置服务器端口优先使用环境变量中的值默认3000
const port = process.env.SERVER_PORT || 3000; const port = process.env.SERVER_PORT || 3000;
// 启动应用,监听指定端口
await app.listen(port); await app.listen(port);
} }
// 启动应用
bootstrap(); bootstrap();

View File

@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';
@Controller('goods')
export class GoodsController {
@Get('hello')
getHello(): string {
return 'Hello World!';
}
}

View File

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { GoodsService } from './goods.service';
import { GoodsController } from './goods.controller';
@Module({
providers: [GoodsService],
controllers: [GoodsController]
})
export class GoodsModule {}

View File

@ -0,0 +1,6 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class GoodsService {
}

View File

@ -1,10 +1,39 @@
import { api } from "@nice/client" import { api } from "@nice/client"
import { useEffect } from "react" import { Button, Tag } from "antd"
import { useEffect, useMemo, useState } from "react"
export default function HomePage() { function HomePage() {
const { data } = api.staff.findMany.useQuery({ take: 10 }) const { data } = api.staff.findMany.useQuery({
take: 10
})
const [counter, setCounter] = useState<number>(0)
const counterText = useMemo(() => {
return `当前计数为:${counter}`
}, [counter])
useEffect(() => { useEffect(() => {
console.log(data) console.log(data)
}, [data]) }, [data])
return <>Home</> return <div className="p-2 space-y-2">
} <Tag>{counterText}</Tag>
<div className="space-x-2" >
<Button type="primary" onClick={() => {
setCounter(counter + 1)
}}>1</Button>
<Button danger
onClick={() => {
setCounter(counter - 1)
}}
>1</Button>
</div>
{
data?.map(i => {
return <div className="p-2 rounded border shadow">
<Tag>{i.username}</Tag>
</div>
})
}
</div>
}
// export { HomePage }
export default HomePage

View File

@ -27,7 +27,8 @@ server {
# 压缩HTTP版本 # 压缩HTTP版本
gzip_http_version 1.1; gzip_http_version 1.1;
# 压缩的文件类型 # 压缩的文件类型
gzip_types text/plain gzip_types
text/plain
text/css text/css
application/json application/json
application/javascript application/javascript
@ -90,8 +91,8 @@ server {
add_header 'Access-Control-Allow-Origin' '$http_origin' always; add_header 'Access-Control-Allow-Origin' '$http_origin' always;
add_header 'Access-Control-Allow-Credentials' 'true' always; add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always; add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' add_header 'Access-Control-Allow-Headers'
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'
always; always;
} }
# 内部认证服务位置 # 内部认证服务位置
@ -110,4 +111,4 @@ server {
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Query-Params $query_string; proxy_set_header X-Query-Params $query_string;
} }
} }

View File

@ -6,7 +6,8 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"dev": "pnpm run --parallel dev", "dev": "pnpm run --parallel dev",
"db:clear": "pnpm --filter common run db:clear" "db:clear": "pnpm --filter common run db:clear",
"studio": "pnpm --filter common run studio"
}, },
"keywords": [], "keywords": [],
"author": "insiinc", "author": "insiinc",

View File

@ -329,3 +329,46 @@ model Resource {
@@index([createdAt]) @@index([createdAt])
@@map("resource") @@map("resource")
} }
//商品表
model Goods {
id String @id @default(cuid()) // 商品ID
name String @unique // 商品名称
description String? // 商品描述
price Float @default(0.0) // 商品价格
images String[] @default([]) // 商品图片
tags Tag[] @relation("GoodsTags") // 多对多关系
reviews Review[] // 一对多关系
createdAt DateTime @default(now()) @map("created_at") // 创建时间
updatedAt DateTime @updatedAt @map("updated_at") // 更新时间
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
@@index([name])
@@map("goods")
}
// 标签表
model Tag {
id String @id @default(cuid())
name String @unique
goods Goods[] @relation("GoodsTags")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@map("tag")
}
model Review {
id String @id @default(cuid())
content String
rating Int @default(0)
goodsId String @map("goods_id")
goods Goods @relation(fields: [goodsId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@index([goodsId])
@@index([rating])
@@map("review")
}