Skip to content

Commit ead8c74

Browse files
committed
1.0
0 parents  commit ead8c74

20 files changed

Lines changed: 2242 additions & 0 deletions

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git
2+
.gitignore
3+
node_modules
4+
npm-debug.log
5+
dist
6+
.env
7+
.env.local
8+
README.md
9+
.vscode
10+
.idea
11+
*.md

.env.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 服务器端口
2+
PORT=3001
3+
4+
# 认证密钥(必需)- 请修改为强密码
5+
AUTH_KEY=your-secret-auth-key-change-this
6+
7+
# 允许的跨域来源(逗号分隔)
8+
# 生产环境请设置具体的域名,例如:https://your-domain.com,https://www.your-domain.com
9+
ALLOWED_ORIGINS=*
10+
11+
# 运行环境
12+
NODE_ENV=production

.eslintrc.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"ecmaVersion": 2022,
5+
"sourceType": "module",
6+
"project": "./tsconfig.json"
7+
},
8+
"plugins": ["@typescript-eslint"],
9+
"extends": [
10+
"eslint:recommended",
11+
"plugin:@typescript-eslint/recommended"
12+
],
13+
"rules": {
14+
"@typescript-eslint/no-explicit-any": "warn",
15+
"@typescript-eslint/explicit-function-return-type": "off",
16+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
17+
"no-console": "off"
18+
},
19+
"env": {
20+
"node": true,
21+
"es2022": true
22+
}
23+
}

.github/workflows/ci-cd.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
lint-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '18'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Run linter
26+
run: npm run lint
27+
28+
- name: Type check
29+
run: npm run typecheck
30+
31+
- name: Build
32+
run: npm run build
33+
34+
build-docker:
35+
runs-on: ubuntu-latest
36+
needs: lint-and-test
37+
if: github.event_name == 'push'
38+
39+
steps:
40+
- uses: actions/checkout@v3
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v2
44+
45+
- name: Login to Docker Hub
46+
uses: docker/login-action@v2
47+
with:
48+
username: ${{ secrets.DOCKER_USERNAME }}
49+
password: ${{ secrets.DOCKER_PASSWORD }}
50+
51+
- name: Build and push
52+
uses: docker/build-push-action@v4
53+
with:
54+
context: .
55+
push: true
56+
tags: |
57+
${{ secrets.DOCKER_USERNAME }}/watch-room-server:latest
58+
${{ secrets.DOCKER_USERNAME }}/watch-room-server:${{ github.sha }}
59+
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/watch-room-server:buildcache
60+
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/watch-room-server:buildcache,mode=max
61+
62+
deploy-fly:
63+
runs-on: ubuntu-latest
64+
needs: lint-and-test
65+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
66+
67+
steps:
68+
- uses: actions/checkout@v3
69+
70+
- name: Setup Fly
71+
uses: superfly/flyctl-actions/setup-flyctl@master
72+
73+
- name: Deploy to Fly.io
74+
run: flyctl deploy --remote-only
75+
env:
76+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Dependencies
2+
node_modules/
3+
package-lock.json
4+
yarn.lock
5+
pnpm-lock.yaml
6+
7+
# Build output
8+
dist/
9+
build/
10+
*.tsbuildinfo
11+
12+
# Environment variables
13+
.env
14+
.env.local
15+
.env.*.local
16+
17+
# Logs
18+
logs/
19+
*.log
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*
23+
pnpm-debug.log*
24+
25+
# OS
26+
.DS_Store
27+
Thumbs.db
28+
29+
# IDE
30+
.vscode/
31+
.idea/
32+
*.swp
33+
*.swo
34+
*~
35+
36+
# Testing
37+
coverage/
38+
.nyc_output/
39+
40+
# Misc
41+
*.pid
42+
*.seed
43+
*.pid.lock

CONTRIBUTING.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# 贡献指南
2+
3+
感谢你对 Watch Room Server 项目的关注!
4+
5+
## 如何贡献
6+
7+
### 报告问题
8+
9+
如果你发现了 bug 或有功能建议:
10+
11+
1. 检查 [Issues](https://github.com/your-repo/watch-room-server/issues) 是否已有相关问题
12+
2. 如果没有,创建新的 Issue
13+
3. 清晰描述问题或建议
14+
4. 提供复现步骤(如果是 bug)
15+
16+
### 提交代码
17+
18+
1. Fork 本仓库
19+
2. 创建你的特性分支 (`git checkout -b feature/AmazingFeature`)
20+
3. 提交你的修改 (`git commit -m 'Add some AmazingFeature'`)
21+
4. 推送到分支 (`git push origin feature/AmazingFeature`)
22+
5. 开启一个 Pull Request
23+
24+
### 代码规范
25+
26+
- 使用 TypeScript
27+
- 遵循 ESLint 规则
28+
- 添加适当的注释
29+
- 保持代码简洁清晰
30+
31+
### 提交信息规范
32+
33+
使用语义化的提交信息:
34+
35+
- `feat:` 新功能
36+
- `fix:` 修复 bug
37+
- `docs:` 文档更新
38+
- `style:` 代码格式调整
39+
- `refactor:` 代码重构
40+
- `test:` 测试相关
41+
- `chore:` 构建/工具相关
42+
43+
示例:
44+
```
45+
feat: 添加房间密码加密功能
46+
fix: 修复心跳检测超时问题
47+
docs: 更新部署文档
48+
```
49+
50+
### 开发流程
51+
52+
1. 安装依赖:`npm install`
53+
2. 启动开发服务器:`npm run dev`
54+
3. 运行 linter:`npm run lint`
55+
4. 类型检查:`npm run typecheck`
56+
5. 构建:`npm run build`
57+
58+
### 测试
59+
60+
在提交 PR 之前,请确保:
61+
62+
- [ ] 代码通过 ESLint 检查
63+
- [ ] TypeScript 类型检查通过
64+
- [ ] 构建成功
65+
- [ ] 功能正常工作
66+
67+
## 行为准则
68+
69+
- 尊重他人
70+
- 保持友善和专业
71+
- 接受建设性批评
72+
- 关注项目最佳利益
73+
74+
## 问题和支持
75+
76+
如有疑问,可以:
77+
78+
- 创建 Issue
79+
- 发送邮件
80+
- 加入讨论组
81+
82+
## 许可证
83+
84+
通过贡献代码,你同意你的贡献将在 MIT 许可证下发布。

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# 使用 Node.js 18 LTS 作为基础镜像
2+
FROM node:18-alpine AS builder
3+
4+
# 设置工作目录
5+
WORKDIR /app
6+
7+
# 复制 package.json 和 lock 文件
8+
COPY package*.json ./
9+
10+
# 安装依赖
11+
RUN npm ci --only=production
12+
13+
# 复制源代码
14+
COPY . .
15+
16+
# 构建 TypeScript
17+
RUN npm run build
18+
19+
# 生产镜像
20+
FROM node:18-alpine
21+
22+
# 设置工作目录
23+
WORKDIR /app
24+
25+
# 复制依赖和构建产物
26+
COPY --from=builder /app/node_modules ./node_modules
27+
COPY --from=builder /app/dist ./dist
28+
COPY --from=builder /app/package.json ./
29+
30+
# 创建非 root 用户
31+
RUN addgroup -g 1001 -S nodejs && \
32+
adduser -S nodejs -u 1001
33+
34+
# 切换到非 root 用户
35+
USER nodejs
36+
37+
# 暴露端口
38+
EXPOSE 3001
39+
40+
# 健康检查
41+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
42+
CMD node -e "require('http').get('http://localhost:3001/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
43+
44+
# 启动应用
45+
CMD ["node", "dist/index.js"]

0 commit comments

Comments
 (0)