I´m working on a project with Node.js API, that have a frontend and a backend. Ich habe already a API-folder inside the frontend, that
await for the get request from the backend and that works for the first method like this:
export const getChange= async () => {
return await axiosDefault.get(controller);
};
Inside the Backend I habe a folder for the Controller.js, index.js and routes.js
So the API comes to the routes and the route link the request to the controller like this:
router.get(
"/",
controller.getChange
);
And the controller take the request:
exports.getChange = async (req, res, next) => {
...
console.log("test getChange");
}
That works completely fine.
But now I want a additional get request route to the controller for the api request getOldNames that I declared like this:
export const getOldNames= async()=> {
}
Now I have to specify the route for this request, but how?
I declared a route like this:
router.get(
"/oldnames",
controller.getOldNames
);
and the controller:
exports.getOldNames = async (req, res, next) => {
...
console.log("test get old names")
}
That doesn´t work this way. I want a different route on the controller. What I have to build this to make it happen? I don´t understand the route mechanic on this point on this point. Why I can on the first request just only pass a "/" and it works. But if I add the "oldnames", it doesn´t work at all? Maybe it is not possible like this, and I have to add a new Controller.js that handles that new get request?
I hope i became clear about my Problems :)
Thank you all !
I have declared some alternative routes with different parameters on the route, also on the controller and api. But nothing work like I want.