Compare commits
10 Commits
95ae569fa0
...
f3dac32a89
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3dac32a89 | ||
|
|
399b9f501b | ||
|
|
30f77a8e9d | ||
|
|
69d2971876 | ||
|
|
43f0891691 | ||
|
|
89ec0abb68 | ||
|
|
46129474b4 | ||
|
|
c89052bd9c | ||
|
|
a1d0a24098 | ||
|
|
dd9b985917 |
11
.env.example
11
.env.example
@ -1,11 +0,0 @@
|
|||||||
# 复制为 .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,7 +13,6 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: https://gitee.com/zsqai/checkout@v4
|
uses: https://gitee.com/zsqai/checkout@v4
|
||||||
|
|
||||||
# 准备环境变量文件:将 .env.production 复制为 .env
|
|
||||||
- name: Prepare .env file for production
|
- name: Prepare .env file for production
|
||||||
run: cp .env.production .env
|
run: cp .env.production .env
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ jobs:
|
|||||||
needs: build-and-push
|
needs: build-and-push
|
||||||
environment:
|
environment:
|
||||||
name: production
|
name: production
|
||||||
url: http://${{ vars.HOST }}:8084
|
url: http://${{ vars.HOST }}
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy via SSH
|
- name: Deploy via SSH
|
||||||
uses: https://gitee.com/zsqai/ssh-action@v1.0.3
|
uses: https://gitee.com/zsqai/ssh-action@v1.0.3
|
||||||
@ -64,17 +63,23 @@ jobs:
|
|||||||
# 拉取最新镜像
|
# 拉取最新镜像
|
||||||
docker pull ${{ vars.ALIYUN_REGISTRY }}/${{ vars.ALIYUN_NAMESPACE }}/${{ vars.ALIYUN_REPO }}:latest
|
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 stop web-01-api 2>/dev/null || true
|
||||||
docker rm web-01-api 2>/dev/null || true
|
docker rm web-01-api 2>/dev/null || true
|
||||||
|
|
||||||
# 启动新容器(不再需要 -e 参数,因为环境变量已打包在镜像内)
|
# 启动新容器(不映射端口到宿主机)
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name web-01-api \
|
--name web-01-api \
|
||||||
--restart always \
|
--restart always \
|
||||||
-p 8084:3003 \
|
--network web-network \
|
||||||
${{ vars.ALIYUN_REGISTRY }}/${{ vars.ALIYUN_NAMESPACE }}/${{ vars.ALIYUN_REPO }}:latest
|
${{ 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
|
docker image prune -f
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ COPY --from=build /app/node_modules ./node_modules
|
|||||||
COPY --from=build /app/dist ./dist
|
COPY --from=build /app/dist ./dist
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
EXPOSE 3002
|
EXPOSE 3003
|
||||||
|
|
||||||
ENTRYPOINT ["dumb-init", "--"]
|
ENTRYPOINT ["dumb-init", "--"]
|
||||||
CMD ["sh", "-c", "set -a; . ./.env; node dist/main"]
|
CMD ["sh", "-c", "set -a; . ./.env; node dist/main"]
|
||||||
@ -52,9 +52,17 @@ export class UploadMiddleware implements NestMiddleware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use(req: Request, _res: Response, next: NextFunction): void {
|
use(req: Request, _res: Response, next: NextFunction): void {
|
||||||
this.upload.single('file')(req, _res, (err) => {
|
// @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) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(new BadRequestException(err.message ?? '文件上传失败'));
|
const msg = err instanceof Error ? err.message : '文件上传失败';
|
||||||
|
next(new BadRequestException(msg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
|
|||||||
@ -158,8 +158,8 @@ async function bootstrap(): Promise<void> {
|
|||||||
await ensureManualTable(app);
|
await ensureManualTable(app);
|
||||||
await ensureManualContentFormatColumn(app);
|
await ensureManualContentFormatColumn(app);
|
||||||
|
|
||||||
const port = parseInt(process.env.PORT ?? '3001', 10);
|
const port = parseInt(process.env.PORT ?? '3003', 10);
|
||||||
await app.listen(port);
|
await app.listen(port,'0.0.0.0');
|
||||||
Logger.log(`🚀 后端服务已启动: http://localhost:${port}`, 'Bootstrap');
|
Logger.log(`🚀 后端服务已启动: http://localhost:${port}`, 'Bootstrap');
|
||||||
Logger.log(`📘 Swagger 文档地址: http://localhost:${port}/api-docs`, 'Bootstrap');
|
Logger.log(`📘 Swagger 文档地址: http://localhost:${port}/api-docs`, 'Bootstrap');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user