Skip to content

Commit

Permalink
fix:node20
Browse files Browse the repository at this point in the history
  • Loading branch information
xizeyoupan committed Mar 16, 2024
1 parent fe4095c commit fd73283
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 571 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ jobs:
unit-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: ['18.x', '19.x', '20.x', '21.x']

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: ${{ matrix.node-version }}

- run: npm i
- run: npm run build:all
Expand Down
27 changes: 8 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@ https://meting-dd.2333332.xyz/test

## 写在前面

Meting后端的api结构较为复杂,基础是一个[接口](https://github.com/metowolf/Meting/blob/master/src/Meting.php),原作者在此基础上增加了[php后端](https://github.com/metowolf/Meting-API/blob/master/api/root/var/www/meting/public/index.php),又用node做了一层[wrapper](https://github.com/metowolf/Meting-API/tree/master/server)
Meting后端的基础是一个[接口](https://github.com/metowolf/Meting/blob/master/src/Meting.php),原作者在此基础上增加了[php后端](https://github.com/metowolf/Meting-API/blob/master/api/root/var/www/meting/public/index.php),又用node做了一层[wrapper](https://github.com/metowolf/Meting-API/tree/master/server)

同时可以发现原作者在docker hub上传了php后端的[镜像](https://hub.docker.com/r/metowolf/meting),但没有node的镜像(仓库中仍有Dockerfile)。

原作者大佬的api服务可能不太稳定,于是我在上面两个Dockerfile的基础上新生成了单一的Dockerfile,仅仅对外暴露一个3000端口。并且微改了一些代码,适配了vercel的serverless function。这个版本在[v1](https://github.com/xizeyoupan/Meting-API/tree/v1)

此版本解决了一些的问题,但可能还有一些问题,比如:

- 依旧不易自行部署
- 对国内的云函数不太适配
- 新的音乐源扩展、维护困难
- 即使在国内访问,如果后端部署在国外,腾讯系音乐仍然无法解析

为此,我开了个新的分支。
同时可以发现原作者在docker hub上传了php后端的[镜像](https://hub.docker.com/r/metowolf/meting),但没有node的镜像(仓库中仍有Dockerfile)。于是重写了一下。

## Feature

Expand Down Expand Up @@ -56,7 +45,7 @@ Meting后端的api结构较为复杂,基础是一个[接口](https://github.co
| youtube music | √² ||
| spotify music | √² ||

youtube和spotify的歌词由于不易访问,由 https://github.com/xizeyoupan/syncedlyrics_aio 检索而来,歌词匹配准确度不会特别高。spotify的音乐源由 https://github.com/spotDL/spotify-downloader 检索而来,歌曲匹配准确度不会很高,并且获取url的时间较长,使spotify歌曲加载缓慢
youtube和spotify的歌词由 https://github.com/xizeyoupan/syncedlyrics_aio 检索而来,歌词匹配准确度不会特别高。spotify的音乐源由 https://github.com/spotDL/spotify-downloader 检索而来,歌曲匹配准确度不会很高,并且获取url的时间较长。

¹使用jsonp,**需要替换前端插件**https://cdn.jsdelivr.net/npm/[email protected]/dist/Meting.min.js => https://cdn.jsdelivr.net/npm/@xizeyoupan/meting@latest/dist/Meting.min.js , or
https://unpkg.com/[email protected]/dist/Meting.min.js => https://unpkg.com/@xizeyoupan/meting@latest/dist/Meting.min.js
Expand Down Expand Up @@ -154,7 +143,7 @@ fork本项目后新建一个[project](https://dash.deno.com/projects),首先
### 反向代理
对于很多HTTP框架的代理来说,只需设置X-Forwarded请求头或transparent proxy。但由于本项目使用了轻量化框架Hono,进行反向代理的时候可能会产生一些令人不适的链接。这里我用了一个自定义的请求头`X-Forwarded-Url`来暴力处理origin和路径的前缀
对于很多HTTP框架的代理来说,只需设置X-Forwarded请求头或transparent proxy。但由于本项目使用了轻量化框架Hono,目前官方似乎还不支持。所以实际有用的的请求头只有`X-Forwarded-Host`

比如我用nginx想让请求 `http://localhost:8099/meting` 的流量全部转发到 `http://localhost:3000` ,直接这么写是不行的:

Expand All @@ -180,7 +169,7 @@ fork本项目后新建一个[project](https://dash.deno.com/projects),首先

location /meting/ {
proxy_pass http://localhost:3000/;
proxy_set_header X-Forwarded-Url $scheme://$host:$server_port/meting;
proxy_set_header X-Forwarded-Host $scheme://$host:$server_port/meting;
}
}
```
Expand All @@ -191,7 +180,7 @@ fork本项目后新建一个[project](https://dash.deno.com/projects),首先
http://localhost:8099 {
handle_path /meting* {
reverse_proxy http://localhost:3000 {
header_up X-Forwarded-Url {scheme}://{host}:{port}/meting
header_up X-Forwarded-Host {scheme}://{host}:{port}/meting
}
}
}
Expand All @@ -216,7 +205,7 @@ fork本项目后新建一个[project](https://dash.deno.com/projects),首先

location /meting/ {
proxy_pass http://localhost:3000/;
proxy_set_header X-Forwarded-Url $scheme://$host:$server_port/meting;
proxy_set_header X-Forwarded-Host $scheme://$host:$server_port/meting;
}
}
```
Expand All @@ -227,7 +216,7 @@ fork本项目后新建一个[project](https://dash.deno.com/projects),首先
tls ./server.crt ./server.key
handle_path /meting* {
reverse_proxy http://localhost:3000 {
header_up X-Forwarded-Url {scheme}://{host}:{port}/meting
header_up X-Forwarded-Host {scheme}://{host}:{port}/meting
}
}
}
Expand Down
35 changes: 34 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,45 @@ import { handler } from './src/template.js'
import { Hono } from 'hono'
import { logger } from 'hono/logger'
import { cors } from 'hono/cors'
import config from './src/config.js'
import { get_runtime, get_url } from './src/util.js'

const app = new Hono()

app.use('*', cors())
app.use('*', logger())
app.get('/api', api)
app.get('/test', handler)
app.get('/', (c) => c.text('你好!访问/test以测试。'))
app.get('/', (c) => {

return c.html(`
<html>
<head>
<title>Meting正在运行</title>
</head>
<body>
<h1>Meting API</h1>
<p>
<a href="https://github.com/xizeyoupan/Meting-API" style="text-decoration: none;">
<img alt="Static Badge" src="https://img.shields.io/badge/Github-Meting-green">
<img alt="GitHub forks" src="https://img.shields.io/github/forks/xizeyoupan/Meting-API">
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/xizeyoupan/Meting-API">
</a>
</p>
<p>当前版本:1.0.7</p>
<p>当前运行环境:${get_runtime()}</p>
<p>当前时间:${new Date()}</p>
<p>内部端口:${config.PORT}</p>
<p>部署在大陆:${config.OVERSEAS ? '否' : '是'}</p>
<p>当前地址:<a>${c.req.url}</a></p>
<p>实际地址:<a>${get_url(c)}</a></p>
<p>测试地址:<a href="${get_url(c) + 'test'}">${get_url(c) + 'test'}</a></p>
<p>api地址:<a href="${get_url(c) + 'api'}">${get_url(c) + 'api'}</a></p>
</body>
</html>`
)
})

export default app
14 changes: 2 additions & 12 deletions node.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { handler } from './src/template.js'
import config from './src/config.js'
import api from './src/service/api.js'
import { Hono } from 'hono'
import { logger } from 'hono/logger'
import { cors } from 'hono/cors'
import { serve } from '@hono/node-server'

const app = new Hono()
app.use('*', cors())
app.use('*', logger())
app.get('/api', api)
app.get('/', (c) => c.text('你好!访问/test以测试。'))
app.get('/test', handler)
import app from './app.js'
import config from './src/config.js'

serve({
fetch: app.fetch,
Expand Down
Loading

0 comments on commit fd73283

Please sign in to comment.