前言
通过Binaryify/NeteaseCloudMusicApi部署网易云音乐API
下载项目
1 2
| git clone https://github.com/Binaryify/NeteaseCloudMusicApi.git cd NeteaseCloudMusicApi
|
下载依赖
运行项目
运行时指定端口号
阻止跨域请求(可选)
- 修改
server.js
第143行,将if (req.path !== '/' && !req.path.includes('.')) {
改为if (["http://<domain>"].includes(req.headers.origin.toLowerCase())) {
,其中http://<domain>
为允许跨域访问的域名,除此之外的域名都不允许跨域访问
1 2 3 4 5 6 7 8 9 10 11 12 13
| app.use((req, res, next) => { if (["http://<domain>"].includes(req.headers.origin.toLowerCase())) { res.set({ 'Access-Control-Allow-Credentials': true, 'Access-Control-Allow-Origin': CORS_ALLOW_ORIGIN || req.headers.origin || '*', 'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type', 'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS', 'Content-Type': 'application/json; charset=utf-8', }) } req.method === 'OPTIONS' ? res.status(204).end() : next() })
|
完成
参考文献
Binaryify/NeteaseCloudMusicApi
Github——Uyoahz26