Updat name - getByDomainName() returns an array

This commit is contained in:
Aarish
2025-05-25 17:14:26 -05:00
parent 57c393d939
commit f86bfee3f3

View File

@@ -44,19 +44,21 @@ router.get('/:id', async function(req, res, next) {
*/ */
router.get('/domain/:domain', async function(req, res, next) { router.get('/domain/:domain', async function(req, res, next) {
const domainName = req.params.domain; const domainName = req.params.domain;
let site = null; let sites = null;
try { try {
site = await siteModel.getByDomainName(domainName); sites = await siteModel.getByDomainName(domainName);
} catch (error) { } catch (error) {
console.error('Error fetching site by domain name:', error); console.error('Error fetching site by domain name:', error);
return res.status(400).send('Error fetching site: ' + error.message); return res.status(400).send('Error fetching site: ' + error.message);
} }
if (!site || site.length === 0) { console.log('Site found:', sites);
if (!sites || sites.length === 0) {
return res.status(404).send('Site not found'); return res.status(404).send('Site not found');
} else { } else {
res.json(site[0]); // Return the first match res.json(sites[0]); // Return the first match
} }
}); });