Comments (11)
from antd-admin.
大佬你好,我有一个关于 Proxy 的问题:
我看了下那些关于调用后端 api 的 issue,如果要使用自己的后端,应该在 services/index.js 里面去给 APIFuction 加。(比如 queryWeather)然后在 .umirc.js 里去改 proxy。
我现在有一个服务器在 localhost:7050 上面跑,比如我要调用 /api/XXX,我试着去改 .umirc.js 关于 queryWeather 的 proxy
proxy: {
'/api/v1/weather': {
target: 'https://localhost:7050',
changeOrigin: true,
pathRewrite: {'^/api/v1/weather/now.json': '/api/XXX' },
},
但是 VSCODE 这边给我报了 [HPM] Error occurred while trying to proxy request /api/XXX from localhost:7000 to https://localhost:7050 (DEPTH_ZERO_SELF_SIGNED_CERT)
前端小白,希望大佬能给点帮助。(后端是 ASP.NET开发的,现在在处理怎么连上后端)
PS: 我尝试在 .umirc.js 加 process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 但是它会报 [HPM] Error occurred while trying to proxy request /api/XXX from localhost:7000 to https://localhost:7050 (ECONNREFUSED)
from antd-admin.
解决方案是:不需要加 process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 但是在 proxy 里添加 secure: false (会接着去尝试)
from antd-admin.
一般来说,前端部署之后,都会直接请求域名,也就是后端接口api。umirc只是开发调试有效
from antd-admin.
大佬的意思是不是直接在 utils/requests.js 里面直接改 domain?我现在想到的是去 utils/config.js 里加,类似 apiPrefix。
(所以说 .umirc 只有在 dev 时有效吗)
from antd-admin.
大佬,我还想问一下,如果我要新增一个 route,能不用修改 mock/route.js 就添加吗。我想直接从后端调数据,而不是去 mock 数据。
from antd-admin.
我现在的做法是:
-
在 mock/route.js 里面添加
然后将 id 加进 mock/user.js 里的 userPermission 中。(这一步下来确实 Menu 栏有 Pictures,但是我感觉这样添加路由的方法很奇怪) -
在 service/index.js 里面添加
backendApp 就是之前后端的域名 https://localhost:7050 -
在 page 下添加 folder picture,然后添加 index.js 和 model.js
我本来以为点击 Pictures 后 model 就会去调用 queryPictures 并且会把 data log 出来,但是 Network 里却没有对应的 request。
(data 类似这样)
求助求助。
from antd-admin.
queryPictures没有触发吗?
pathToRegexp('/picture').exec(location.pathname)
看的别扭。直接location.pathname =='/picture'就行
from antd-admin.
对,没有触发。我以为应该会有类似点击 Dashboard 时 network 里的 request。
但是什么都没有。我发现 const data = yield call(queryPictures, payload) 这一步之后就不再运行了。
from antd-admin.
好吧,我太笨了。我把那个请求放到 try catch里面发现我 service/index.js 里面有一个变量没有引入。
但是我还是想问一下,如果 mock 只在 dev 中生效,那么应该怎么去添加一个新的 route?我试着在 package.json 用 "start": "MOCK=none umi dev" 但是它给我报错了
(就我比较担心的是,现在大部分的组件都依赖 mock 文件的运行,如果 mock 在 production 情况下是无效的,那应该怎么办,是不是我得在后端搭建类似 queryRouteList 这样的 api?因为我感觉它约定式路由没有生效)
from antd-admin.
嗯,我想出来了,谢谢
from antd-admin.
Related Issues (20)
- Failed to load resource: the server responded with a status of 404 (Not Found) 开发环境是正常的,打包后浏览器打开出问题 HOT 3
- 自己写登录接口 HOT 1
- 强强
- 能否提供个typescript版的 HOT 1
- 切换菜单时报错
- 项目启动时报 [ERR_ASSERTION]: filePath not found of antd/lib/locale-provider/pt_BR
- 启动直接报错,我的node版本是18.12.1 HOT 3
- 有没有项目说明文档 HOT 2
- 打开之后无法加载页面 HOT 2
- 111
- Select tag mode bug HOT 1
- npm run start doesn't work HOT 5
- macbook中出现Assertion Error,无法npm run start HOT 3
- develop分支,修改主题色无效 HOT 2
- 技术问题,怎么实现受控表单 HOT 2
- Demo Prevew version diffirence git clone version? HOT 2
- pageing not working HOT 1
- graphgl HOT 1
- auto focus on modal open HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from antd-admin.