File tree Expand file tree Collapse file tree 7 files changed +610
-389
lines changed Expand file tree Collapse file tree 7 files changed +610
-389
lines changed Original file line number Diff line number Diff line change
1
+ name : Publish Docker image
2
+
3
+ on :
4
+ release :
5
+ types : [published]
6
+
7
+ jobs :
8
+ push_to_registry :
9
+ name : Push Docker image to multiple registries
10
+ runs-on : ubuntu-latest
11
+ permissions :
12
+ packages : write
13
+ contents : read
14
+ steps :
15
+ - name : Check out the repo
16
+ uses : actions/checkout@v4
17
+
18
+ - name : Log in to Docker Hub
19
+ uses : docker/login-action@v3
20
+ with :
21
+ username : ${{ secrets.DOCKER_USERNAME }}
22
+ password : ${{ secrets.DOCKER_PASSWORD }}
23
+
24
+ - name : Log in to the Container registry
25
+ uses : docker/login-action@v3
26
+ with :
27
+ registry : ghcr.io
28
+ username : ${{ github.actor }}
29
+ password : ${{ secrets.GITHUB_TOKEN }}
30
+
31
+ - name : Extract metadata (tags, labels) for Docker
32
+ id : meta
33
+ uses : docker/metadata-action@v5
34
+ with :
35
+ images : |
36
+ imsyy/dailyhot-api
37
+ ghcr.io/${{ github.repository }}
38
+
39
+ - name : Build and push Docker image
40
+ uses : docker/build-push-action@v5
41
+ with :
42
+ context : .
43
+ file : ./Dockerfile
44
+ push : true
45
+ tags : ${{ steps.meta.outputs.tags }}
46
+ labels : ${{ steps.meta.outputs.labels }}
Original file line number Diff line number Diff line change 1
- FROM node:16 -alpine
1
+ FROM node:18 -alpine
2
2
WORKDIR /app
3
3
4
4
COPY package*.json ./
Original file line number Diff line number Diff line change @@ -117,6 +117,8 @@ pnpm start
117
117
docker build -t dailyhot-api .
118
118
# 运行
119
119
docker run -p 6688:6688 -d dailyhot-api
120
+ # 或使用 Docker Compose
121
+ docker-compose up -d
120
122
```
121
123
122
124
### 在线部署
Original file line number Diff line number Diff line change
1
+ services :
2
+ DailyhotApi :
3
+ build :
4
+ context : .
5
+ image : dailyhot-api
6
+ container_name : dailyhot-api
7
+ volumes :
8
+ - /etc/localtime:/etc/localtime:ro
9
+ - /etc/timezone:/etc/timezone:ro
10
+ ports :
11
+ - 6688:6688
12
+ restart : always
Original file line number Diff line number Diff line change @@ -27,18 +27,28 @@ app.use(
27
27
} ) ,
28
28
) ;
29
29
30
+ // CORS
30
31
app . use ( async ( ctx , next ) => {
31
- if ( domain === "*" ) {
32
- await next ( ) ;
32
+ ctx . set ( "Access-Control-Allow-Origin" , domain ) ;
33
+ ctx . set ( "Access-Control-Allow-Methods" , "GET, OPTIONS" ) ;
34
+ ctx . set ( "Access-Control-Allow-Headers" , "Content-Type, Authorization" ) ;
35
+ ctx . set ( "Access-Control-Allow-Credentials" , "true" ) ;
36
+ // 处理预检请求
37
+ if ( ctx . method === "OPTIONS" ) {
38
+ ctx . status = 200 ;
33
39
} else {
34
- if ( ctx . headers . origin === domain || ctx . headers . referer === domain ) {
40
+ if ( domain === "*" ) {
35
41
await next ( ) ;
36
42
} else {
37
- ctx . status = 403 ;
38
- ctx . body = {
39
- code : 403 ,
40
- message : "请通过正确的域名访问" ,
41
- } ;
43
+ if ( ctx . headers . origin === domain || ctx . headers . referer === domain ) {
44
+ await next ( ) ;
45
+ } else {
46
+ ctx . status = 403 ;
47
+ ctx . body = {
48
+ code : 403 ,
49
+ message : "请通过正确的域名访问" ,
50
+ } ;
51
+ }
42
52
}
43
53
}
44
54
} ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " dailyhot_api" ,
3
- "version" : " 1.0.7 " ,
3
+ "version" : " 1.0.8 " ,
4
4
"description" : " An api on Today's Hot list" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
14
14
"author" : " imsyy" ,
15
15
"license" : " MIT" ,
16
16
"dependencies" : {
17
- "axios" : " ^1.3.4 " ,
17
+ "axios" : " ^1.6.3 " ,
18
18
"cheerio" : " 1.0.0-rc.12" ,
19
- "dotenv" : " ^16.0.3 " ,
20
- "eslint" : " ^8.48 .0" ,
21
- "eslint-plugin-vue" : " ^9.17.0 " ,
22
- "koa" : " ^2.14.1 " ,
23
- "koa-bodyparser" : " ^4.3.0 " ,
24
- "koa-router" : " ^12.0.0 " ,
19
+ "dotenv" : " ^16.3.1 " ,
20
+ "eslint" : " ^8.56 .0" ,
21
+ "eslint-plugin-vue" : " ^9.19.2 " ,
22
+ "koa" : " ^2.15.0 " ,
23
+ "koa-bodyparser" : " ^4.4.1 " ,
24
+ "koa-router" : " ^12.0.1 " ,
25
25
"koa-static" : " ^5.0.0" ,
26
- "koa-views" : " ^8.0 .0" ,
26
+ "koa-views" : " ^8.1 .0" ,
27
27
"koa2-cors" : " ^2.0.6" ,
28
28
"node-cache" : " ^5.1.2" ,
29
29
"nodemon" : " ^2.0.22" ,
30
- "prettier" : " ^3.0.2 "
30
+ "prettier" : " ^3.1.1 "
31
31
}
32
32
}
You can’t perform that action at this time.
0 commit comments