fix: 调整mock默认路由 (#8108)
* fix: 调整mock默认路由 1. starting改为running 语义更明确 2. API地址修复 3. 列表顺序调整,登录接口靠前 * docs: 替换axios调用示例 原先/api/user接口地址不对,且是受认证保护的接口,响应异常容易造成误解
This commit is contained in:
@@ -3,13 +3,13 @@ import { defineEventHandler } from 'h3';
|
||||
export default defineEventHandler(() => {
|
||||
return `
|
||||
<h1>Hello Vben Admin</h1>
|
||||
<h2>Mock service is starting</h2>
|
||||
<h2>Mock service is running</h2>
|
||||
<ul>
|
||||
<li><a href="/api/user">/api/user/info</a></li>
|
||||
<li><a href="/api/menu">/api/menu/all</a></li>
|
||||
<li><a href="/api/auth/codes">/api/auth/codes</a></li>
|
||||
<li><a href="/api/auth/login">/api/auth/login</a></li>
|
||||
<li><a href="/api/upload">/api/upload</a></li>
|
||||
<li><a href="/api/auth/codes">/api/auth/codes</a></li>
|
||||
<li><a href="/api/user/info">/api/user/info</a></li>
|
||||
<li><a href="/api/menu/all">/api/menu/all</a></li>
|
||||
<li><a href="/api/auth/logout">/api/auth/logout</a></li>
|
||||
</ul>
|
||||
`;
|
||||
});
|
||||
|
||||
@@ -63,16 +63,18 @@ Based on the above configuration, we can use `/api` as the prefix for API reques
|
||||
```ts
|
||||
import axios from 'axios';
|
||||
|
||||
axios.get('/api/user').then((res) => {
|
||||
console.log(res);
|
||||
});
|
||||
axios
|
||||
.post('/api/auth/login', { username: 'vben', password: '123456' })
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
});
|
||||
```
|
||||
|
||||
At this point, the request will be proxied to `http://localhost:5320/api/user`.
|
||||
At this point, the request will be proxied to `http://localhost:5320/api/auth/login`.
|
||||
|
||||
::: warning Note
|
||||
|
||||
From the browser's console Network tab, the request appears as `http://localhost:5555/api/user`. This is because the proxy configuration does not change the local request's URL.
|
||||
From the browser's console Network tab, the request appears as `http://localhost:5555/api/auth/login`. This is because the proxy configuration does not change the local request's URL.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
@@ -63,16 +63,18 @@ export default defineConfig(async () => {
|
||||
```ts
|
||||
import axios from 'axios';
|
||||
|
||||
axios.get('/api/user').then((res) => {
|
||||
console.log(res);
|
||||
});
|
||||
axios
|
||||
.post('/api/auth/login', { username: 'vben', password: '123456' })
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
});
|
||||
```
|
||||
|
||||
此时,请求会被代理到 `http://localhost:5320/api/user`。
|
||||
此时,请求会被代理到 `http://localhost:5320/api/auth/login`。
|
||||
|
||||
::: warning 注意
|
||||
|
||||
从浏览器控制台的 Network 看,请求是 `http://localhost:5555/api/user`, 这是因为 proxy 配置不会改变本地请求的 url。
|
||||
从浏览器控制台的 Network 看,请求是 `http://localhost:5555/api/auth/login`, 这是因为 proxy 配置不会改变本地请求的 url。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
Reference in New Issue
Block a user