-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c1fcadf
Showing
20 changed files
with
3,565 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
kind: pipeline | ||
type: docker | ||
name: default | ||
|
||
steps: | ||
- name: test | ||
image: 18-alpine3.15 | ||
commands: | ||
- yarn | ||
- yarn test | ||
|
||
- name: docker-build | ||
image: plugins/docker | ||
settings: | ||
repo: liuchuzhang/blue-music-be | ||
tags: latest | ||
username: | ||
from_secret: docker_username | ||
password: | ||
from_secret: docker_password | ||
|
||
- name: deploy | ||
image: appleboy/drone-ssh | ||
environment: | ||
SSH_DEPLOY_SHELL: | ||
from_secret: ssh_deploy_shell | ||
settings: | ||
host: | ||
from_secret: ssh_host | ||
port: | ||
from_secret: ssh_port | ||
username: | ||
from_secret: ssh_username | ||
password: | ||
from_secret: ssh_password | ||
envs: | ||
- ssh_deploy_shell | ||
script: | ||
- $SSH_DEPLOY_SHELL -d music -e liuchuzhang/blue-music-be -i music-be -p 4001 -u /api | ||
|
||
trigger: | ||
branch: | ||
- main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
FROM node:18-alpine3.15 | ||
ENV NODE_ENV=production | ||
|
||
WORKDIR /app | ||
|
||
COPY ["package.json", "yarn.lock*", "./"] | ||
|
||
RUN yarn | ||
|
||
COPY . . | ||
|
||
EXPOSE 4001 | ||
CMD ["yarn", "server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# blue-music-be | ||
|
||
## Usage | ||
|
||
```shell | ||
yarn && yarn dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import axios from 'axios' | ||
import { stopServer } from './helpers/server' | ||
|
||
afterAll(() => { | ||
stopServer() | ||
}) | ||
|
||
describe('hello', () => { | ||
it('world', async () => { | ||
const res = await axios.get('http://localhost:4001/api/hello/world') | ||
expect(1 + 199).toEqual(200) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { exec } from 'child_process' | ||
import { delay } from './utils' | ||
import app from '../../src/app' | ||
|
||
const server = app.listen(4001) | ||
|
||
export const stopServer = async () => { | ||
server.close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
export const delay = (time?: number) => new Promise(r => setTimeout(r, time || 3000)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import axios from 'axios' | ||
import { stopServer } from './helpers/server' | ||
|
||
afterAll(() => { | ||
stopServer() | ||
}) | ||
|
||
describe('proxy', () => { | ||
it('kuwo', async () => { | ||
const res = await axios.get('http://localhost:4001/api/kuwo') | ||
expect(res.status).toEqual(200) | ||
}) | ||
|
||
it('163', async () => { | ||
const res = await axios.get('http://localhost:4001/api/music163/api/artist/10559') | ||
expect(res.status).toEqual(200) | ||
}) | ||
|
||
it('migu', async () => { | ||
const res = await axios.get('http://localhost:4001/api/appcnfmigu/MIGUM3.0/v1.0/template/rank-list/release?dataVersion=1616469593718&templateVersion=9') | ||
expect(res.status).toEqual(200) | ||
}) | ||
|
||
it('migu', async () => { | ||
const res = await axios.get('http://localhost:4001/api/cyqq/v8/fcg-bin/fcg_myqq_toplist.fcg?g_tk=5381&inCharset=utf-8&outCharset=utf-8¬ice=0&format=json&uin=0&needNewCode=1&platform=h5') | ||
expect(res.status).toEqual(200) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
testMatch: ["**/__test__/**/*.test.ts"], | ||
transform: { | ||
'^.+\\.(t|j)sx?$': ['@swc-node/jest'], | ||
}, | ||
globals: { | ||
"ts-jest": { | ||
tsconfig: "tsconfig.test.json", | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "blue-music-be", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "nodemon -r @swc-node/register src/server.ts", | ||
"test": "jest", | ||
"server": "node -r @swc-node/register src/server.ts" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@types/express": "^4.17.13", | ||
"address": "^1.1.2", | ||
"axios": "^0.27.2", | ||
"express": "^4.18.1", | ||
"http-proxy-middleware": "^2.0.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.8.3" | ||
}, | ||
"devDependencies": { | ||
"@swc-node/jest": "^1.5.2", | ||
"@swc-node/register": "^1.5.1", | ||
"@types/jest": "^29.0.0", | ||
"jest": "^29.0.2", | ||
"nodemon": "^2.0.19" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import express from 'express' | ||
import { proxy, hello } from './routes' | ||
|
||
const app = express() | ||
|
||
app.use('/api', proxy) | ||
app.use('/api/hello', hello) | ||
|
||
export default app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './proxy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
export interface ProxyItem { | ||
prefix: string | ||
target: string | ||
domain?: string | ||
} | ||
|
||
export const proxyList: ProxyItem[] = [ | ||
{ | ||
prefix: '/uyqq', | ||
target: 'https://u.y.qq.com' | ||
}, | ||
{ | ||
prefix: '/cyqq', | ||
target: 'https://c.y.qq.com' | ||
}, | ||
{ | ||
prefix: '/music163', | ||
target: 'https://music.163.com' | ||
}, | ||
{ | ||
prefix: '/kuwo', | ||
target: 'https://www.kuwo.cn' | ||
}, | ||
{ | ||
prefix: '/kwroot/root', | ||
target: 'https://www.kuwo.cn', | ||
domain: 'www.kuwo.cn' | ||
}, | ||
{ | ||
prefix: '/songsearchkugou', | ||
target: 'https://songsearch.kugou.com' | ||
}, | ||
{ | ||
prefix: '/apibilibili', | ||
target: 'https://api.bilibili.com' | ||
}, | ||
{ | ||
prefix: '/jadeitemigu', | ||
target: 'https://jadeite.migu.cn' | ||
}, | ||
{ | ||
prefix: '/interface3', | ||
target: 'https://interface3.music.163.com' | ||
}, | ||
{ | ||
prefix: '/iyqq', | ||
target: 'https://i.y.qq.com' | ||
}, | ||
{ | ||
prefix: '/antiserverkuwo', | ||
target: 'https://antiserver.kuwo.cn' | ||
}, | ||
{ | ||
prefix: '/appcnfmigu', | ||
target: 'https://app.c.nf.migu.cn' | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import express, { Response, Request } from 'express' | ||
|
||
const router = express.Router() | ||
|
||
router.get('/world', (req: Request, res: Response, next) => { | ||
res.send('Hello World') | ||
}) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as hello } from './hello' | ||
export { default as proxy } from './proxy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import express from 'express' | ||
import { createProxyMiddleware } from 'http-proxy-middleware' | ||
import { ProxyItem, proxyList } from '../constants' | ||
|
||
const router = express.Router() | ||
|
||
const getKuwoProxy = (): ProxyItem[] => { | ||
const array26 = Array(26).fill(null) | ||
return array26.map((_, first) => array26.map((_, second) => { | ||
const keyword = String.fromCharCode(97 + first) + String.fromCharCode(97 + second) | ||
|
||
return { | ||
prefix: `/${keyword}sycdnkuwo`, | ||
target: `http://${keyword}.sycdn.kuwo.cn` | ||
} | ||
})).flat() | ||
} | ||
|
||
proxyList.concat(getKuwoProxy()).forEach(item => { | ||
const host = item.target.replace(/^http[s]?:\/\//, '') | ||
|
||
router.use( | ||
item.prefix, | ||
createProxyMiddleware({ | ||
target: item.target, | ||
changeOrigin: true, | ||
pathRewrite: { | ||
[`^/api${item.prefix}`]: '' | ||
}, | ||
cookieDomainRewrite: { | ||
'*': item.domain || '' | ||
}, | ||
cookiePathRewrite: { | ||
'*': '/' | ||
}, | ||
headers: { | ||
Referer: item.target, | ||
Host: host, | ||
'sec-ch-ua': '"Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"', | ||
'User-Agent': | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36' | ||
} | ||
}) | ||
) | ||
}) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import address from 'address' | ||
import app from './app' | ||
|
||
app.listen(4001) | ||
|
||
console.log(`server start on http://${address.ip()}:4001`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"module": "CommonJS", | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"esModuleInterop": true, | ||
"allowJs": true, | ||
"allowSyntheticDefaultImports": true, | ||
"types": ["node"] | ||
}, | ||
"include": ["*.ts", "./**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"types": ["node", "jest"] | ||
}, | ||
"extends": "./tsconfig.json", | ||
"include": ["./__test__/*.ts", "./__test__/**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
Oops, something went wrong.