mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-24 22:10:12 +08:00
使用.env代替config.js
This commit is contained in:
parent
2caed48fa5
commit
aadb1be17a
1
.env.example
Normal file
1
.env.example
Normal file
|
@ -0,0 +1 @@
|
|||
VUE_APP_NETEASE_API_URL=http://localhost:3000
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,6 +4,7 @@ node_modules
|
|||
|
||||
|
||||
# local env files
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
|
|
|
@ -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
|
||||
- 播放记录
|
||||
- 无限播放模式(播放完列表后自动播放相似歌曲)
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* The base url of your API.
|
||||
*
|
||||
* The API can be found at https://github.com/Binaryify/NeteaseCloudMusicApi
|
||||
*/
|
||||
export const baseURL = "";
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user