To test client's ApiService
class I need to replace my real backend URL by a mock and for these purposes I chose json-server. I set up a proxy config to forward all requests that starts with http://localhost:4200/v1/api
to http://localhost:3000
:
{
"/api/v1": {
"target": "http://localhost:3000",
"secure": false
}
}
And it works when I send requests like http://localhost:4200/api/v1/users
BUT not for nested endpoints (e.g. http://localhost:4200/api/v1/auth/token
). I found that json-server doesn't support requests to nested objects so I changed my data.json as below:
{
"auth_token": {
"access_token":"accesstoken1",
"token_type":"Bearer"
}
}
And set up routes.json for json-server:
{
"/auth/token": "/auth_token"
}
But it doesn't work still through json-server uses routes.json:
[0] Other routes
[0] /auth/token -> /auth_token
What am I doing wrong?