I add
proxy: {
"/api": {
"target": "http://jsonplaceholder.typicode.com/",
"changeOrigin": true,
"pathRewrite": { "^/api" : "" }
}
},
to config.js but not working.
@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-mockthen 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.jsproxy: { '/api': { target: 'http://api.car.local/', changeOrigin: true, pathRewrite: { '^/api': '' } } }service api
/src/services/api.jsexport 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.
Most helpful comment
@TranDucBlog
hello,it's work. this is my configure
added into /config/config.js
service api
/src/services/api.js
the origin API "http://api.car.local/wechat/member/sign-in"
and then run without mock