Skip to content

Commit

Permalink
docs: 增加部署到vercel后api跨域的解决方法
Browse files Browse the repository at this point in the history
  • Loading branch information
qier222 committed Sep 25, 2021
1 parent b052b46 commit cc914d4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ NeteaseCloudMusicApi-master
NeteaseCloudMusicApi-master.zip

# Local Netlify folder
.netlify
.netlify
vercel.json
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
Electron 版本由 [@hawtim](https://github.com/hawtim)[@qier222](https://github.com/qier222) 适配并维护,支持 macOS、Windows、Linux。

访问本项目的 [Releases](https://github.com/qier222/YesPlayMusic/releases)
页面下载安装包,或者访问 [镜像下载站 (大陆访问更快)](https://dl.qier222.com/YesPlayMusic/) 下载
页面下载安装包。

macOS 用户也可以通过 `brew install --cask yesplaymusic` 来安装。

Expand All @@ -54,13 +54,26 @@ macOS 用户也可以通过 `brew install --cask yesplaymusic` 来安装。

2. 点击本仓库右上角的 Fork,复制本仓库到你的 GitHub 账号。

3. 打开 [Vercel.com](https://vercel.com),使用 GitHub 登录。
3. 点击仓库的 Add File,选择 Create new file,输入 `vercel.json`,将下面的内容复制粘贴到文件中,并将 `https://your-netease-api.example.com` 替换为你刚刚部署的网易云 API 地址:

```json
{
"rewrites": [
{
"source": "/api/:match*",
"destination": "https://your-netease-api.example.com/:match*"
}
]
}
```

4. 打开 [Vercel.com](https://vercel.com),使用 GitHub 登录。

4. 点击 Import Git Repository 并选择你刚刚复制的仓库并点击 Import。
5. 点击 Import Git Repository 并选择你刚刚复制的仓库并点击 Import。

5. 点击 PERSONAL ACCOUNT 旁边的 Select。
6. 点击 PERSONAL ACCOUNT 旁边的 Select。

6. 点击 Environment Variables,填写 Name 为 `VUE_APP_NETEASE_API_URL`,Value 为你刚刚部署的网易云 API 地址,点击 Add。最后点击底部的 Deploy 就可以部署到
7. 点击 Environment Variables,填写 Name 为 `VUE_APP_NETEASE_API_URL`,Value `/api`,点击 Add。最后点击底部的 Deploy 就可以部署到
Vercel 了。

## ⚙️ 部署到自己的服务器
Expand Down Expand Up @@ -127,7 +140,7 @@ yarn run build

```shell
# 安装依赖
yarn
yarn install

# 创建本地环境变量
cp .env.example .env
Expand Down
8 changes: 8 additions & 0 deletions vercel.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rewrites": [
{
"source": "/api/:match*",
"destination": "https://your-netease-api.example.com/:match*"
}
]
}

0 comments on commit cc914d4

Please sign in to comment.