Updat name - getByDomainName() returns an array
This commit is contained in:
@@ -44,19 +44,21 @@ router.get('/:id', async function(req, res, next) {
|
||||
*/
|
||||
router.get('/domain/:domain', async function(req, res, next) {
|
||||
const domainName = req.params.domain;
|
||||
let site = null;
|
||||
let sites = null;
|
||||
|
||||
try {
|
||||
site = await siteModel.getByDomainName(domainName);
|
||||
sites = await siteModel.getByDomainName(domainName);
|
||||
} catch (error) {
|
||||
console.error('Error fetching site by domain name:', error);
|
||||
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');
|
||||
} else {
|
||||
res.json(site[0]); // Return the first match
|
||||
res.json(sites[0]); // Return the first match
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user