Git Product home page Git Product logo

Comments (11)

LDD123 avatar LDD123 commented on May 28, 2024

from antd-admin.

Hongda-OSU avatar Hongda-OSU commented on May 28, 2024

大佬你好,我有一个关于 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.

Hongda-OSU avatar Hongda-OSU commented on May 28, 2024

解决方案是:不需要加 process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 但是在 proxy 里添加 secure: false (会接着去尝试)

from antd-admin.

superlbr avatar superlbr commented on May 28, 2024

一般来说,前端部署之后,都会直接请求域名,也就是后端接口api。umirc只是开发调试有效

from antd-admin.

Hongda-OSU avatar Hongda-OSU commented on May 28, 2024

大佬的意思是不是直接在 utils/requests.js 里面直接改 domain?我现在想到的是去 utils/config.js 里加,类似 apiPrefix。

(所以说 .umirc 只有在 dev 时有效吗)

from antd-admin.

Hongda-OSU avatar Hongda-OSU commented on May 28, 2024

大佬,我还想问一下,如果我要新增一个 route,能不用修改 mock/route.js 就添加吗。我想直接从后端调数据,而不是去 mock 数据。

from antd-admin.

Hongda-OSU avatar Hongda-OSU commented on May 28, 2024

我现在的做法是:

  1. 在 mock/route.js 里面添加
    Screenshot 2023-06-02 231032
    然后将 id 加进 mock/user.js 里的 userPermission 中。(这一步下来确实 Menu 栏有 Pictures,但是我感觉这样添加路由的方法很奇怪)

  2. 在 service/index.js 里面添加
    Screenshot 2023-06-02 231400
    backendApp 就是之前后端的域名 https://localhost:7050

  3. 在 page 下添加 folder picture,然后添加 index.js 和 model.js
    Screenshot 2023-06-02 231832
    Screenshot 2023-06-02 231947
    我本来以为点击 Pictures 后 model 就会去调用 queryPictures 并且会把 data log 出来,但是 Network 里却没有对应的 request。
    Screenshot 2023-06-02 233025 (data 类似这样)

求助求助。

from antd-admin.

superlbr avatar superlbr commented on May 28, 2024

queryPictures没有触发吗?
pathToRegexp('/picture').exec(location.pathname) 看的别扭。直接location.pathname =='/picture'就行

from antd-admin.

Hongda-OSU avatar Hongda-OSU commented on May 28, 2024

对,没有触发。我以为应该会有类似点击 Dashboard 时 network 里的 request。
Screenshot 2023-06-03 134641
但是什么都没有。我发现 const data = yield call(queryPictures, payload) 这一步之后就不再运行了。

from antd-admin.

Hongda-OSU avatar Hongda-OSU commented on May 28, 2024

好吧,我太笨了。我把那个请求放到 try catch里面发现我 service/index.js 里面有一个变量没有引入。

但是我还是想问一下,如果 mock 只在 dev 中生效,那么应该怎么去添加一个新的 route?我试着在 package.json 用 "start": "MOCK=none umi dev" 但是它给我报错了
Screenshot 2023-06-03 170705
(就我比较担心的是,现在大部分的组件都依赖 mock 文件的运行,如果 mock 在 production 情况下是无效的,那应该怎么办,是不是我得在后端搭建类似 queryRouteList 这样的 api?因为我感觉它约定式路由没有生效)

from antd-admin.

Hongda-OSU avatar Hongda-OSU commented on May 28, 2024

嗯,我想出来了,谢谢

from antd-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.