🐳 chore: 支持自动部署
This commit is contained in:
parent
3343f2b5db
commit
b7260cf569
46
.github/workflows/docker.yml
vendored
Normal file
46
.github/workflows/docker.yml
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
name: Publish Docker image
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
push_to_registry:
|
||||
name: Push Docker image to multiple registries
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
packages: write
|
||||
contents: read
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
imsyy/dailyhot-api
|
||||
ghcr.io/${{ github.repository }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
@ -1,4 +1,4 @@
|
||||
FROM node:16-alpine
|
||||
FROM node:18-alpine
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
|
@ -117,6 +117,8 @@ pnpm start
|
||||
docker build -t dailyhot-api .
|
||||
# 运行
|
||||
docker run -p 6688:6688 -d dailyhot-api
|
||||
# 或使用 Docker Compose
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### 在线部署
|
||||
|
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@ -0,0 +1,12 @@
|
||||
services:
|
||||
DailyhotApi:
|
||||
build:
|
||||
context: .
|
||||
image: dailyhot-api
|
||||
container_name: dailyhot-api
|
||||
volumes:
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
ports:
|
||||
- 6688:6688
|
||||
restart: always
|
26
index.js
26
index.js
@ -27,18 +27,28 @@ app.use(
|
||||
}),
|
||||
);
|
||||
|
||||
// CORS
|
||||
app.use(async (ctx, next) => {
|
||||
if (domain === "*") {
|
||||
await next();
|
||||
ctx.set("Access-Control-Allow-Origin", domain);
|
||||
ctx.set("Access-Control-Allow-Methods", "GET, OPTIONS");
|
||||
ctx.set("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
||||
ctx.set("Access-Control-Allow-Credentials", "true");
|
||||
// 处理预检请求
|
||||
if (ctx.method === "OPTIONS") {
|
||||
ctx.status = 200;
|
||||
} else {
|
||||
if (ctx.headers.origin === domain || ctx.headers.referer === domain) {
|
||||
if (domain === "*") {
|
||||
await next();
|
||||
} else {
|
||||
ctx.status = 403;
|
||||
ctx.body = {
|
||||
code: 403,
|
||||
message: "请通过正确的域名访问",
|
||||
};
|
||||
if (ctx.headers.origin === domain || ctx.headers.referer === domain) {
|
||||
await next();
|
||||
} else {
|
||||
ctx.status = 403;
|
||||
ctx.body = {
|
||||
code: 403,
|
||||
message: "请通过正确的域名访问",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dailyhot_api",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"description": "An api on Today's Hot list",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -14,19 +14,19 @@
|
||||
"author": "imsyy",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^1.3.4",
|
||||
"axios": "^1.6.3",
|
||||
"cheerio": "1.0.0-rc.12",
|
||||
"dotenv": "^16.0.3",
|
||||
"eslint": "^8.48.0",
|
||||
"eslint-plugin-vue": "^9.17.0",
|
||||
"koa": "^2.14.1",
|
||||
"koa-bodyparser": "^4.3.0",
|
||||
"koa-router": "^12.0.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-plugin-vue": "^9.19.2",
|
||||
"koa": "^2.15.0",
|
||||
"koa-bodyparser": "^4.4.1",
|
||||
"koa-router": "^12.0.1",
|
||||
"koa-static": "^5.0.0",
|
||||
"koa-views": "^8.0.0",
|
||||
"koa-views": "^8.1.0",
|
||||
"koa2-cors": "^2.0.6",
|
||||
"node-cache": "^5.1.2",
|
||||
"nodemon": "^2.0.22",
|
||||
"prettier": "^3.0.2"
|
||||
"prettier": "^3.1.1"
|
||||
}
|
||||
}
|
||||
|
893
pnpm-lock.yaml
893
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user