Calls from my ionic app to my backend don't work on the smartphone. They work in the browser and in the emulator, but when I install the apk on the smartphone, it doesn't work.
My frontend is in ionic with capacitor.
My backend is java with Springboot.
This is my backend call:
url = `${SERVER_URL}/recipe`;
constructor(private httpClient: HttpClient, private alertController: AlertController) { }
findByIngredients(urlIds): Observable<Recipe[]> {
return this.httpClient.get<Recipe[]>(this.url + urlIds)
.pipe(
retry(2),
catchError(this.handleError))
}
findLastTen(): Observable<Recipe[]> {
return this.httpClient.get<Recipe[]>(`${this.url}/lastTen`)
.pipe(
retry(2),
catchError(this.handleError))
}
This is my backend cors configuration:
@Configuration
public class CorsConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "TRACE");
}
}
This is one of my endpoints:
@RestController
@RequestMapping("/recipe")
public class RecipeController {
@Autowired
private RecipeFacade facade;
@GetMapping(value = "/lastTen")
public ResponseEntity<List<GetAllRecipesDTO>> getLastTenRecipes() {
List<GetAllRecipesDTO> dto = facade.getLastTenRecipes();
return new ResponseEntity<>(dto, HttpStatus.OK);
}
Error message that is returned:
http failure response for http://...:9000/recipe/lastTen: 0 Unknown Error