Service:
import { Injectable } from '@angular/core';
import { HttpHeaders, HttpClient } from '@angular/common/http';
constructor(
private http: HttpClient
) { }
private API_GET_BARCO_BY_CANTIDAD = `${GlobalVariables.URL_NODE}/barco/encontrar/c/?barcosC=`;
private header = new HttpHeaders({
'Content-Type': 'application/json'
});
public getBarcoByC(cantidad: Number): Observable<any> {
return this.http.get<any>(this.API_GET_BARCO_BY_CANTIDAD + cantidad, { headers: this.header });
}
API:
const router = Router();
const Barco = require('../models/Barco')
router.get("/barco/encontrar/c/", getBarcosByC);
async function getBarcoBy(req, res) {
try {
let id = req.params.id;
const barco = await Barco.findById(id, function (err, docs) {
if (err) {
console.log(`n[BarcosApi Error] Found Barco By Id(${id}):n`,err)
} else {
console.log(`n[BarcosApi] Found Barco By Id(${id}):n`, docs)
}
}).clone().catch(function (err) { console.log(err) })
if ('err' in barco) return res.status(barco.codestatus).json(barco.err);
return res.status(200).json(barco);
} catch (err) {
console.log("[BarcosApi] getBarcoByError", err);
}
}
Console: temp0.error.text
Gives back the whole index.html page as error.text
All GET requests have the same respond(index.html), while POST, UPDATE, DELETE works flawlessly