Skip to content

Commit 1aa115e

Browse files
committed
支持服务自动部署
1 parent 1a6a25f commit 1aa115e

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

.github/workflows/deploy.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Deploy to Server
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v3
13+
14+
- name: Setup SSH
15+
uses: webfactory/ssh-agent@v0.8.0
16+
with:
17+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
18+
19+
- name: Add host key
20+
run: |
21+
mkdir -p ~/.ssh
22+
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
23+
24+
- name: Deploy to server
25+
env:
26+
SERVER_IP: ${{ secrets.SERVER_IP }}
27+
SERVER_USER: ${{ secrets.SERVER_USER }}
28+
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
29+
run: |
30+
# 将代码复制到服务器
31+
rsync -avz --delete ./ $SERVER_USER@$SERVER_IP:$DEPLOY_PATH
32+
33+
# SSH 连接服务器并重启应用
34+
ssh $SERVER_USER@$SERVER_IP "cd $DEPLOY_PATH && \
35+
docker-compose down && \
36+
docker-compose up -d --build"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mockaroo",
3-
"version": "1.0.0",
4-
"description": "HTTP Mock 服务器",
3+
"version": "2025.1.0",
4+
"description": "一个轻量级的 HTTP Mock 服务器,用于快速构建模拟数据接口,适用于前端开发和接口测试场景。",
55
"main": "src/mockaroo.js",
66
"scripts": {
77
"start": "nodemon src/mockaroo.js"

src/routes/posts.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ router.get('/', (req, res) => {
77
// 从查询参数获取 limit,如果没有则默认为 100
88
const limit = parseInt(req.query.limit) || 100;
99

10-
// 生成文章数据
11-
const posts = generatePosts(limit);
12-
13-
// 返回响应
14-
res.json({
15-
code: 200,
16-
message: 'success',
17-
data: posts
18-
});
10+
res.json(generatePosts(limit));
1911
});
2012

2113
module.exports = router;

0 commit comments

Comments
 (0)