Ant-design-pro: V2, Config proxy not working

Created on 5 Sep 2018  ·  9Comments  ·  Source: ant-design/ant-design-pro

I add
proxy: { "/api": { "target": "http://jsonplaceholder.typicode.com/", "changeOrigin": true, "pathRewrite": { "^/api" : "" } } },
to config.js but not working.

Most helpful comment

@TranDucBlog
hello,it's work. this is my configure
added into /config/config.js

 proxy: {
    '/api': {
      target: 'http://api.car.local/',
      changeOrigin: true,
      pathRewrite: {
        '^/api': ''
      }
    }
  }

service api
/src/services/api.js

export async function fakeAccountLogin(params) {
  return request('/api/wechat/member/sign-in', {
    method: 'POST',
    body: params,
  });

the origin API "http://api.car.local/wechat/member/sign-in"

and then run without mock

npm run start:no-mock

All 9 comments

@chenshuai2144 I added the proxy to the config.js file, so that is not correct? What should I do to make it work?

@TranDucBlog try start npm without mock

npm run start:no-mock

@mailbaoer I want to use the api from the server, instead of localhost: 8000 using domain.com/api, is my method correct, or do I have to do it differently?

@TranDucBlog
hello,it's work. this is my configure
added into /config/config.js

 proxy: {
    '/api': {
      target: 'http://api.car.local/',
      changeOrigin: true,
      pathRewrite: {
        '^/api': ''
      }
    }
  }

service api
/src/services/api.js

export async function fakeAccountLogin(params) {
  return request('/api/wechat/member/sign-in', {
    method: 'POST',
    body: params,
  });

the origin API "http://api.car.local/wechat/member/sign-in"

and then run without mock

npm run start:no-mock

when i run without mock

npm run start:no-mock

then my page are not found, redirect to 404 error page

when i run without mock

npm run start:no-mock

then my page are not found, redirect to 404 error page

I encountered the same problem, do you know how to fix it ?

Same Problem, After Build, 404 page error.

@TranDucBlog
hello,it's work. this is my configure
added into /config/config.js

 proxy: {
    '/api': {
      target: 'http://api.car.local/',
      changeOrigin: true,
      pathRewrite: {
        '^/api': ''
      }
    }
  }

service api
/src/services/api.js

export async function fakeAccountLogin(params) {
  return request('/api/wechat/member/sign-in', {
    method: 'POST',
    body: params,
  });

the origin API "http://api.car.local/wechat/member/sign-in"

and then run without mock

npm run start:no-mock

I try this one good work on localhost but, when I try to umi build the project, It not work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lvzheng0404 picture lvzheng0404  ·  3Comments

Jerry-goodboy picture Jerry-goodboy  ·  3Comments

cheung1111 picture cheung1111  ·  3Comments

happier2 picture happier2  ·  3Comments

yjz1004 picture yjz1004  ·  3Comments