i am developing an endpoint extension. it is loading properly but it when I try to hit through browser or or curl command it is throwing an error
async function discoverDevices() {
// Replace with actual discovery logic
return [
{ id: 1, status: 'active', device_name: 'Device 1', ip_address: '192.168.1.1' },
{ id: 2, status: 'inactive', device_name: 'Device 2', ip_address: '192.168.1.2' },
];
}
async function updateControllerCollection() {
const itemsService = new ItemsService('controller');
try {
const devices = await discoverDevices();
for (const device of devices) {
await itemsService.createOne(device);
}
logger.info('Devices successfully stored in the controller collection.');
} catch (error) {
logger.error('Error storing devices in the controller collection:', error);
}
}
router.post('/', async (req, res) => {
try {
await updateControllerCollection();
res.status(200).send({ message: 'Device discovery triggered successfully.' });
} catch (error) {
logger.error('Error triggering device discovery:', error);
res.status(500).send({ message: 'Error triggering device discovery.' });
}
});
},