Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

refactor(server): 使伺服器可以復用、更換廢棄函式 #1453

Merged
merged 10 commits into from
Jan 27, 2022

Conversation

pan93412
Copy link
Contributor

@pan93412 pan93412 commented Jan 26, 2022

我們需要 NCM API 的伺服器部分,但 app.js 目前的做法讓我們不太好單獨啟動伺服器。因此,我將 app.js 的伺服器部分抽成各個函數,並將原有會 blocking 的函數更改為非同步函式。這樣不僅能最大化善用 Node.js 的 Event Loop,亦能提升未來維護的程式碼易讀性。

同時,有鑒於 Express 4.x 以上版本已經內建 body-parser,我將 bodyParser 更改為內建函數。

注意:有 breaking changes:有鑒於原本 main.js 的功能已經整合進 server.js,我直接將 main 切換成 main.js 的超集——server.js。但所有使用 main.js 原 API 的呼叫者都 必須 改呼叫 getModulesDefinitions()(回傳格式稍有不同)。

我們需要 NCM API 的伺服器部分,但 app.js
目前的做法讓我們不太好單獨啟動伺服器。

我將 app.js 的伺服器部分抽成各個函數,並將原有
會 blocking 的函數更改為非同步函式。
這樣不僅能最大化善用 Node.js 的 Event Loop,
亦能提升未來維護的程式碼易讀性。
Express 4.x 以上版本已經內建 body-parser。
@vercel
Copy link

vercel bot commented Jan 26, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

netease-cloud-music-api – ./docs

🔍 Inspect: https://vercel.com/binaryify/netease-cloud-music-api/ABA9nHT3zAQcN2zDB2dz1nNDtwDb
✅ Preview: https://netease-cloud-music-api-git-fork-pan93412-refa-9b88a1-binaryify.vercel.app

netease-cloud-music-api-binaryify – ./

🔍 Inspect: https://vercel.com/binaryify/netease-cloud-music-api-binaryify/EFpR5PEi6LraDBk8LTFYAotrWzKk
✅ Preview: https://netease-cloud-music-api-binaryify-git-fork-pan-df2555-binaryify.vercel.app

自行維護 require 名單以相容 Webpack。
I'm going to replace the function of "main.js".
server.js 有 main.js 原本的功能 (getModulesDefinitions)

BREAKING CHANGES: 所有使用到這個 lib 的應用程式
,皆需更改為 .getModulesDefinitions()。
@pan93412
Copy link
Contributor Author

r? @Binaryify

@pan93412 pan93412 marked this pull request as ready for review January 26, 2022 07:43
pan93412 added a commit to qier222/YesPlayMusic that referenced this pull request Jan 26, 2022
also:
  - docs: tells user to clone repo recursively
  - feat(ci): clone recursively
  - feat(ncmapi): backport my change
    Binaryify/NeteaseCloudMusicApi#1453
  - refactor: rewrite startNeteaseMusicApi()
@Binaryify
Copy link
Owner

可以的兄弟,不过今天有点忙,明天我review下

@Binaryify Binaryify merged commit 36942a3 into Binaryify:master Jan 27, 2022
@pan93412 pan93412 deleted the refactor/server-seperation branch January 27, 2022 02:50
@Binaryify
Copy link
Owner

为了兼容以前nodejs调用模块的写法
image
我把这段加了回来
https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/server.js#L298

@pan93412
Copy link
Contributor Author

https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/server.js#L298

👌 那你這樣改回來的話就沒 breaking changes 了,可以降回 4.x

SasaVelickovic pushed a commit to SasaVelickovic/MediaPlayer that referenced this pull request Nov 26, 2023
also:
  - docs: tells user to clone repo recursively
  - feat(ci): clone recursively
  - feat(ncmapi): backport my change
    Binaryify/NeteaseCloudMusicApi#1453
  - refactor: rewrite startNeteaseMusicApi()
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants