Compare commits
No commits in common. "f3dac32a893837e90de361993adea1a3b222f09a" and "95ae569fa012da8f8a283d37d18fc7c4ac30f109" have entirely different histories.
f3dac32a89
...
95ae569fa0
11
.env.example
Normal file
11
.env.example
Normal file
@ -0,0 +1,11 @@
|
||||
# 复制为 .env 并按需修改
|
||||
PORT=3001
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_USER=root
|
||||
DB_PASSWORD=root
|
||||
DB_NAME=corp_website
|
||||
JWT_SECRET=corp_website_secret_key_2026ai
|
||||
JWT_EXPIRES_IN=7d
|
||||
UPLOAD_ROOT=./uploads
|
||||
NODE_ENV=development
|
||||
@ -13,6 +13,7 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: https://gitee.com/zsqai/checkout@v4
|
||||
|
||||
# 准备环境变量文件:将 .env.production 复制为 .env
|
||||
- name: Prepare .env file for production
|
||||
run: cp .env.production .env
|
||||
|
||||
@ -41,7 +42,7 @@ jobs:
|
||||
needs: build-and-push
|
||||
environment:
|
||||
name: production
|
||||
url: http://${{ vars.HOST }}
|
||||
url: http://${{ vars.HOST }}:8084
|
||||
steps:
|
||||
- name: Deploy via SSH
|
||||
uses: https://gitee.com/zsqai/ssh-action@v1.0.3
|
||||
@ -63,23 +64,17 @@ jobs:
|
||||
# 拉取最新镜像
|
||||
docker pull ${{ vars.ALIYUN_REGISTRY }}/${{ vars.ALIYUN_NAMESPACE }}/${{ vars.ALIYUN_REPO }}:latest
|
||||
|
||||
# 确保 Docker 网络存在
|
||||
docker network inspect web-network >/dev/null 2>&1 || docker network create web-network
|
||||
|
||||
# 停止并删除旧容器
|
||||
docker stop web-01-api 2>/dev/null || true
|
||||
docker rm web-01-api 2>/dev/null || true
|
||||
|
||||
# 启动新容器(不映射端口到宿主机)
|
||||
# 启动新容器(不再需要 -e 参数,因为环境变量已打包在镜像内)
|
||||
docker run -d \
|
||||
--name web-01-api \
|
||||
--restart always \
|
||||
--network web-network \
|
||||
-p 8084:3003 \
|
||||
${{ vars.ALIYUN_REGISTRY }}/${{ vars.ALIYUN_NAMESPACE }}/${{ vars.ALIYUN_REPO }}:latest
|
||||
|
||||
# 将 NPM 容器连接到同一网络(如果还没连接)
|
||||
docker network connect web-network nginx-proxy-manager 2>/dev/null || true
|
||||
|
||||
# 清理旧镜像
|
||||
docker image prune -f
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ COPY --from=build /app/node_modules ./node_modules
|
||||
COPY --from=build /app/dist ./dist
|
||||
COPY package*.json ./
|
||||
|
||||
EXPOSE 3003
|
||||
EXPOSE 3002
|
||||
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
CMD ["sh", "-c", "set -a; . ./.env; node dist/main"]
|
||||
@ -52,17 +52,9 @@ export class UploadMiddleware implements NestMiddleware {
|
||||
}
|
||||
|
||||
use(req: Request, _res: Response, next: NextFunction): void {
|
||||
// @types/express 与 @types/multer 内嵌的 @types/express-serve-static-core 版本不一致,
|
||||
// 运行时完全等价,用 unknown 中转两次绕过编译期差异
|
||||
const single = this.upload.single('file') as unknown as (
|
||||
req: Request,
|
||||
res: Response,
|
||||
cb: (err: unknown) => void,
|
||||
) => void;
|
||||
single(req, _res, (err) => {
|
||||
this.upload.single('file')(req, _res, (err) => {
|
||||
if (err) {
|
||||
const msg = err instanceof Error ? err.message : '文件上传失败';
|
||||
next(new BadRequestException(msg));
|
||||
next(new BadRequestException(err.message ?? '文件上传失败'));
|
||||
return;
|
||||
}
|
||||
next();
|
||||
|
||||
@ -158,8 +158,8 @@ async function bootstrap(): Promise<void> {
|
||||
await ensureManualTable(app);
|
||||
await ensureManualContentFormatColumn(app);
|
||||
|
||||
const port = parseInt(process.env.PORT ?? '3003', 10);
|
||||
await app.listen(port,'0.0.0.0');
|
||||
const port = parseInt(process.env.PORT ?? '3001', 10);
|
||||
await app.listen(port);
|
||||
Logger.log(`🚀 后端服务已启动: http://localhost:${port}`, 'Bootstrap');
|
||||
Logger.log(`📘 Swagger 文档地址: http://localhost:${port}/api-docs`, 'Bootstrap');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user