i don\'t understand where i am wrong .
ps. already try to fix by this answer but still not working
Angular-CLI proxy to backend doesn't work
Con
change
{
"/api": {
"target": "http://localhost:1234",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
to
{
"/api": {
"target": "http://localhost:1234",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"pathRewrite": {
"^/api": ""
}
}
}
You're matching only /api
url. If you want to match urls that begin with /api
but have something else use /api/*
.
{
"/api/*": {
"target": "http://localhost:1234",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
This configuration will proxy from local-server (lets suppose it is localhost:4200
) to your target, so:
localhost:4200/api
--> http://localhost:1234/api
localhost:4200/api/product
--> http://localhost:1234/api/product
localhost:4200
--> no proxylocalhost:4200/whatever
--> no proxyIf you want to exclude /api/
from the target route, include pathRewrite
inside in proxy.config.json
:
{
"/api/*": {
"target": "http://localhost:1234",
"pathRewrite": { "^/api": "" },
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}