使用.env代替config.js

master
qier222 4 years ago
parent 2caed48fa5
commit aadb1be17a

@ -0,0 +1 @@
VUE_APP_NETEASE_API_URL=http://localhost:3000

1
.gitignore vendored

@ -4,6 +4,7 @@ node_modules
# local env files # local env files
.env
.env.local .env.local
.env.*.local .env.*.local

@ -44,16 +44,16 @@ git clone https://github.com/qier222/YesPlayMusic.git
npm install 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. 编译打包 5. 编译打包
```sh ```sh
npm build npm run build
``` ```
6. 将 `/dist` 目录下的文件上传到你的 Web 服务器 6. 将 `/dist` 目录下的文件上传到你的 Web 服务器
@ -62,6 +62,7 @@ npm build
- 中文支持 - 中文支持
- Dark Mode - Dark Mode
- 歌词
- 私人 FM - 私人 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 axios from "axios";
import { baseURL } from "@/config/request";
const service = axios.create({ const service = axios.create({
baseURL: baseURL, baseURL: process.env.VUE_APP_NETEASE_API_URL,
withCredentials: true, withCredentials: true,
timeout: 15000, timeout: 15000
}); });
const errors = new Map([ const errors = new Map([
[401, 'The token you are using has expired.'], [401, "The token you are using has expired."],
[502, null], [502, null],
[301, 'You must login to use this feature.'], [301, "You must login to use this feature."],
[-1, 'An unexpected error has occurred: '], [-1, "An unexpected error has occurred: "]
]); ]);
service.interceptors.response.use( service.interceptors.response.use(
(response) => { response => {
const res = response.data; const res = response.data;
if (res.code !== 200) { if (res.code !== 200) {
alert( alert(
errors.has(res.code) errors.has(res.code)
? errors.get(res.code) ? errors.get(res.code) ||
// null = `The server returned ${res.msg}` // null = `The server returned ${res.msg}`
|| `The server returned ${res.msg}` `The server returned ${res.msg}`
// -1 = default expection message : // -1 = default expection message
: errors.get(-1) + res.code errors.get(-1) + res.code
); );
} else { } else {
return res; return res;
} }
}, },
(error) => { error => {
const errMsg = `error: ${error}`; const errMsg = `error: ${error}`;
console.log(errMsg); console.log(errMsg);

Loading…
Cancel
Save