I am trying to send a get request from the client to the server in order to later take the necessary data from the database. For XMLHttpRequests I use the axios library. The problem is that the request is not sent, the console displays: GET http: // localhost: 3000 / items 404 (Not Found). Error: Request failed with status code 404. What could be the error?

Клиентская часть: <script> export default { data(){ return{ items: [] } }, created: function() { this.fetchItems(); }, methods: { fetchItems (){ let uri = '/items'; this.axios.get(uri).then((response) => { this.items = response.data.items; }); } } } </script> 

Server part:

 var express = require('express'); var app = express(); var itemRoutes = express.Router(); itemRoutes.route('/items').get(function (req, res) { res.send('GET request to the homepage'); }); 

    1 answer 1

    If the server and the client are on different ports, then when accessing the client to the server in the path, you must specify the full path to the port

     let uri = 'http://localhost:[порт сервера]/items'; this.axios.get(uri) 

    PS I advise you not to use axios and go to fetch.

    • Please try to leave a little more detailed answers. You can add an answer by clicking edit - aleksandr barakin