diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..ab14a6b --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +VUE_APP_NETEASE_API_URL=http://localhost:3000 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3557e17..3736680 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules # local env files +.env .env.local .env.*.local diff --git a/README.md b/README.md index b81b731..a8fa474 100644 --- a/README.md +++ b/README.md @@ -44,16 +44,16 @@ git clone https://github.com/qier222/YesPlayMusic.git npm install ``` -4. 替换 `/src/config/request.js` 里面 `baseURL` 的值为网易云 API 地址 +4. 复制 `/.env.example` 文件为 `/.env`,修改里面 `VUE_APP_NETEASE_API_URL` 的值为网易云 API 地址。本地开发的话可以填写 API 地址为 `http://localhost:3000`,YesPlayMusic 地址为 `http://localhost:8080` -```JS -baseURL: "http://example.com", +``` +VUE_APP_NETEASE_API_URL=http://localhost:3000 ``` 5. 编译打包 ```sh -npm build +npm run build ``` 6. 将 `/dist` 目录下的文件上传到你的 Web 服务器 @@ -62,6 +62,7 @@ npm build - 中文支持 - Dark Mode +- 歌词 - 私人 FM - 播放记录 - 无限播放模式(播放完列表后自动播放相似歌曲) diff --git a/src/config/request.js b/src/config/request.js deleted file mode 100644 index bac58ec..0000000 --- a/src/config/request.js +++ /dev/null @@ -1,6 +0,0 @@ -/** - * The base url of your API. - * - * The API can be found at https://github.com/Binaryify/NeteaseCloudMusicApi - */ -export const baseURL = ""; \ No newline at end of file diff --git a/src/utils/request.js b/src/utils/request.js index 7c9c333..bfecc67 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,37 +1,36 @@ import axios from "axios"; -import { baseURL } from "@/config/request"; const service = axios.create({ - baseURL: baseURL, + baseURL: process.env.VUE_APP_NETEASE_API_URL, withCredentials: true, - timeout: 15000, + timeout: 15000 }); const errors = new Map([ - [401, 'The token you are using has expired.'], + [401, "The token you are using has expired."], [502, null], - [301, 'You must login to use this feature.'], - [-1, 'An unexpected error has occurred: '], + [301, "You must login to use this feature."], + [-1, "An unexpected error has occurred: "] ]); service.interceptors.response.use( - (response) => { + response => { const res = response.data; if (res.code !== 200) { alert( errors.has(res.code) - ? errors.get(res.code) - // null = `The server returned ${res.msg}` - || `The server returned ${res.msg}` - // -1 = default expection message - : errors.get(-1) + res.code + ? errors.get(res.code) || + // null = `The server returned ${res.msg}` + `The server returned ${res.msg}` + : // -1 = default expection message + errors.get(-1) + res.code ); } else { return res; } }, - (error) => { + error => { const errMsg = `error: ${error}`; console.log(errMsg);