How to use ant-design-pro Local Server api, does not use mock

mock, is used in ant-design-pro. I don"t want to use mock, to test my local api server with nodejs.

I banned mock in .uplohogrc.mock.js

// 
// const noProxy = process.env.NO_PROXY === "true";
const noProxy = true

Save and refresh the web page and find that the mock data is really gone. Then I added

to ant-design-pro "s package.json.
"proxy": "http://localhost:9000",

I used to do the same with create-react-app. As long as node has a server listening to port 9000, I can debug api, but it doesn"t seem to work in ant-design-pro. Fetch is always 404.

the normal situation is as follows. This is the 3000 I accessed with create-react-app, the 3000 monitored by create-react-app, and the local port 9000 accessed using proxy:

clipboard.png

clipboard.png
create-react-app

ant-design-proant-design-pro8001proxy9000:
clipboard.png

clipboard.png
ant-design-proapiapi

clipboard.png
tell me how to use the local server api, instead of mock.
Thank the gods for their help!

Mar.14,2021

Let me answer it myself. ant-design-pro has in the official document

.

however, there is something wrong with the document, and many people have stepped on this hole in the issue of the official guihub. The solution is as follows:


// .roadhogrc.mock.js
export default {
  'GET /api/*': 'https://your.server.com/api/',
};

export default {
  'GET /api/*': 'https://your.server.com/',
};
api
export default {
  '/*': 'https://your.server.com/',
};

it's a bit rude to write this directly, in case you have to manually change it back if you want to use mock in the future, in fact, the official has already made the startup command.

// .roadhogrc.mock.js
const noProxy = (process.env.NO_PROXY === 'true');
...
export default noProxy ? {} : delay(proxy, 1000);
NO_PROXYtrue

if you start the project: npm start, directly, then NO_PROXY is false, and you can start it: npm start:no-proxy

package.json:
"start": "roadhog server",
"start:no-proxy": "cross-env NO_PROXY=true roadhog server"

then the trinomial operation above derives {}. Just write in the redirected domain name, as follows:

export default (noProxy
  ? { "/*": "https://your.server.com/" }
  : delay(proxy, 1000));
< hr >

2018-8-28 add:

after a long time, I came back to read the post and saw that some of my friends still did not succeed. Post my actual code

.
export default (noProxy ? {
  'POST /lazer/*': 'http://localhost:7001/',
  'GET /download/*': 'http://localhost:7001/',
} : delay(proxy, 1000));

correct posture! .roomhogrc.mock.js

// 
// const noProxy = process.env.NO_PROXY === 'true';
const noProxy =true;
const apiurl="http://192.168.1.204:8800";
export default noProxy ? {
  'GET /api/(.*)': apiurl+'/api/',
  'POST /api/(.*)': apiurl+'/api/',
} : delay(proxy, 1000);

remove the proxy from the package.json directly, and write the api address you want to visit as localhost:9000/url


const noProxy = (process.env.NO_PROXY = 'true');
' GET / api/currentUser': {

$desc: "",
$params: {
  pageSize: {
    desc: '',
    exp: 2,
  },
},
$body: {
  name: 'Serati Ma',
  avatar: 'https://img.codeshelper.com/upload/img/2021/03/14/tlbazs125yx8457.png',
  userid: '00000001',
  notifyCount: 12,
},

},
.
export default (noProxy
? {https://api-v5.segmentfault.com/question/"/ *": "http://test.servcer.com"}
: delay (proxy, 1000));

what if the request is still sent to localhost:8080 after configuration

Can

agents cross domains? I
export default noProxy? {
'GET / api/ (. *)': apiurl+'/api/',
'POST / api/ (. *)': apiurl+'/api/',
}: delay (proxy, 1000).


@ Yang de Chao can part of mock be true?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bdc091-312b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bdc091-312b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?