multy-stub/server/routers/old/my/index.js

30 lines
956 B
JavaScript
Raw Permalink Normal View History

2024-05-24 05:04:31 +03:00
const router = require('express').Router();
router.get('/catalog-data', (request, response) => {
2024-05-25 12:44:44 +03:00
response.send(require('./stubs/json/catalog-data/success.json'))
2024-05-24 05:04:31 +03:00
})
2024-05-25 12:44:44 +03:00
router.get('/item-data', (request, response) => {
response.send(require('./stubs/json/catalog-data/newsuccess.json'))
2024-05-24 05:04:31 +03:00
})
2024-05-25 12:44:44 +03:00
router.post('/search', (request, response) => {
const searchTerm = request.body.search.toLowerCase();
try {
const itemsData = require('./stubs/json/catalog-data/newsuccess.json');
const itemData = itemsData.data.find(item => item.name.toLowerCase().includes(searchTerm));
if (itemData) {
return response.json({ data: itemData });
} else {
console.log('Item not found');
return response.status(404).send('Item not found');
}
} catch (error) {
console.error('Error reading file:', error);
return response.status(500).send('Internal server error');
}
});
2024-05-24 05:04:31 +03:00
2024-05-25 12:44:44 +03:00
module.exports = router;