From 8743e216c9b2466fc5387ee1f97cf47ce83a9f89 Mon Sep 17 00:00:00 2001 From: binaryify Date: Wed, 18 Jan 2023 15:47:24 +0800 Subject: [PATCH] =?UTF-8?q?axios=20=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=B0=83=E6=95=B4,=20=E8=85=BE=E8=AE=AF=E4=BA=91=20serverless?= =?UTF-8?q?=20=E9=83=A8=E7=BD=B2=E6=96=87=E6=A1=A3=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.MD | 16 ++++++++++++++++ docs/README.md | 17 +++++++++++++++++ plugins/songUpload.js | 2 +- plugins/upload.js | 2 +- scf_bootstrap | 3 +++ test/album.test.js | 2 +- test/comment.test.js | 2 +- test/lyric.test.js | 2 +- test/music_url.test.js | 2 +- test/search.test.js | 2 +- 10 files changed, 43 insertions(+), 7 deletions(-) create mode 100755 scf_bootstrap diff --git a/README.MD b/README.MD index 97adf35345f..b44213417b4 100644 --- a/README.MD +++ b/README.MD @@ -74,6 +74,22 @@ v4.0.8 加入了 Vercel 配置文件,可以直接在 Vercel 下部署了,不需 5. 直接点`Continue` 6. `PROJECT NAME`自己填,`FRAMEWORK PRESET` 选 `Other` 然后直接点 `Deploy` 接着等部署完成即可 +## 腾讯云 serverless 部署 +因 `Vercel` 在国内访问太慢,在此提供腾讯云 serverless 部署方法 +### 操作方法 +1. fork 此项目 +2. 在腾讯云serverless应用管理页面(https://console.cloud.tencent.com/sls),点击`新建应用` +3. 顶部`创建方式`选择 `Web 应用` +4. 选择 `Express框架`,点击底部`下一步按钮` +5. 输入`应用名`,上传方式选择`代码仓库`,进行GitHub授权(如已授权可跳过这一步),代码仓库选择刚刚fork的项目 +6. 启动文件填入: +``` +#!/bin/bash +export PORT=9000 +/var/lang/node16/bin/node app.js +``` +7. 点击`完成`,等待部署完成,点击`资源列表`的 `API网关` 里的 `URL`,正常情况会打开文档地址,点击文档`例子`可查看接口调用效果 + ## 可以在Node.js调用 v3.31.0后支持Node.js调用,导入的方法为`module`内的文件名,返回内容包含`status`和`body`,`status`为状态码,`body`为请求返回内容,参考`module_example` 文件夹下的 `test.js` diff --git a/docs/README.md b/docs/README.md index cf9b2d0e34f..04adcc6a7a8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -334,6 +334,23 @@ v4.0.8 加入了 Vercel 配置文件,可以直接在 Vercel 下部署了,不需 5. 直接点`Continue` 6. `PROJECT NAME`自己填,`FRAMEWORK PRESET` 选 `Other` 然后直接点 `Deploy` 接着等部署完成即可 + +## 腾讯云 serverless 部署 +因 `Vercel` 在国内访问太慢,在此提供腾讯云 serverless 部署方法 +### 操作方法 +1. fork 此项目 +2. 在腾讯云serverless应用管理页面(https://console.cloud.tencent.com/sls),点击`新建应用` +3. 顶部`创建方式`选择 `Web 应用` +4. 选择 `Express框架`,点击底部`下一步按钮` +5. 输入`应用名`,上传方式选择`代码仓库`,进行GitHub授权(如已授权可跳过这一步),代码仓库选择刚刚fork的项目 +6. 启动文件填入: +``` +#!/bin/bash +export PORT=9000 +/var/lang/node16/bin/node app.js +``` +7. 点击`完成`,等待部署完成,点击`资源列表`的 `API网关` 里的 `URL`,正常情况会打开文档地址,点击文档`例子`可查看接口调用效果 + ## 可以使用代理 在 query 参数中加上 proxy=your-proxy 即可让这一次的请求使用 proxy diff --git a/plugins/songUpload.js b/plugins/songUpload.js index cd91a748512..fc59700c92c 100644 --- a/plugins/songUpload.js +++ b/plugins/songUpload.js @@ -1,4 +1,4 @@ -const axios = require('axios') +const { default: axios } = require('axios') module.exports = async (query, request) => { let ext = 'mp3' if (query.songFile.name.indexOf('flac') > -1) { diff --git a/plugins/upload.js b/plugins/upload.js index cddb52bdd70..a4035534937 100644 --- a/plugins/upload.js +++ b/plugins/upload.js @@ -1,4 +1,4 @@ -const axios = require('axios') +const { default: axios } = require('axios') module.exports = async (query, request) => { const data = { bucket: 'yyimgs', diff --git a/scf_bootstrap b/scf_bootstrap new file mode 100755 index 00000000000..0d8f5993863 --- /dev/null +++ b/scf_bootstrap @@ -0,0 +1,3 @@ +#!/bin/bash +export PORT=9000 +/var/lang/node16/bin/node app.js diff --git a/test/album.test.js b/test/album.test.js index 25d7d3bcdcb..58632c4c921 100644 --- a/test/album.test.js +++ b/test/album.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const axios = require('axios') +const { default: axios } = require('axios') const host = global.host || 'http://localhost:3000' const config = require('../util/config.json') describe('测试获取歌手专辑列表是否正常', () => { diff --git a/test/comment.test.js b/test/comment.test.js index 5aa0fbcdd40..39ccf6814d0 100644 --- a/test/comment.test.js +++ b/test/comment.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const axios = require('axios') +const { default: axios } = require('axios') const host = global.host || 'http://localhost:3000' const config = require('../util/config.json') describe('测试获取评论是否正常', () => { diff --git a/test/lyric.test.js b/test/lyric.test.js index b185ab5f370..017f2cdc3b7 100644 --- a/test/lyric.test.js +++ b/test/lyric.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const axios = require('axios') +const { default: axios } = require('axios') const host = global.host || 'http://localhost:3000' const config = require('../util/config.json') describe('测试获取歌词是否正常', () => { diff --git a/test/music_url.test.js b/test/music_url.test.js index 90837ee261e..bfa85d263d1 100644 --- a/test/music_url.test.js +++ b/test/music_url.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const axios = require('axios') +const { default: axios } = require('axios') const host = global.host || 'http://localhost:3000' const config = require('../util/config.json') describe('测试获取歌曲是否正常', () => { diff --git a/test/search.test.js b/test/search.test.js index 73d6237583b..efd90c7341b 100644 --- a/test/search.test.js +++ b/test/search.test.js @@ -1,5 +1,5 @@ const assert = require('assert') -const axios = require('axios') +const { default: axios } = require('axios') const host = global.host || 'http://localhost:3000' const config = require('../util/config.json') describe('测试搜索是否正常', () => {