This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const express = require('express');
|
||||
const { fetchHtml } = require('./scraper');
|
||||
const { fetchHtml, extractSeo, extractMetaTags } = require('./scraper');
|
||||
const dbOps = require('./database');
|
||||
const { authenticateApiKey } = require('./middleware');
|
||||
const { isBrowserConnected } = require('./browser');
|
||||
@@ -81,4 +81,78 @@ router.delete('/cache', authenticateApiKey, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// SEO extraction endpoint
|
||||
router.get('/seo', authenticateApiKey, async (req, res) => {
|
||||
const { url, skipCache } = req.query;
|
||||
|
||||
// Validate URL parameter
|
||||
if (!url) {
|
||||
return res.status(400).json({
|
||||
error: 'Missing required parameter: url',
|
||||
});
|
||||
}
|
||||
|
||||
// Validate URL format
|
||||
let urlObj;
|
||||
try {
|
||||
urlObj = new URL(url);
|
||||
} catch (error) {
|
||||
return res.status(400).json({
|
||||
error: 'Invalid URL format',
|
||||
});
|
||||
}
|
||||
|
||||
// Parse skipCache (accept 'true', '1', 'yes', etc.)
|
||||
const shouldSkipCache = skipCache === 'true' || skipCache === '1' || skipCache === 'yes';
|
||||
|
||||
try {
|
||||
const seoData = await extractSeo(url, shouldSkipCache);
|
||||
res.json(seoData);
|
||||
} catch (error) {
|
||||
console.error('SEO extraction error:', error);
|
||||
res.status(500).json({
|
||||
status: 'error',
|
||||
url: url,
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Meta tags extraction endpoint
|
||||
router.get('/meta', authenticateApiKey, async (req, res) => {
|
||||
const { url, skipCache } = req.query;
|
||||
|
||||
// Validate URL parameter
|
||||
if (!url) {
|
||||
return res.status(400).json({
|
||||
error: 'Missing required parameter: url',
|
||||
});
|
||||
}
|
||||
|
||||
// Validate URL format
|
||||
let urlObj;
|
||||
try {
|
||||
urlObj = new URL(url);
|
||||
} catch (error) {
|
||||
return res.status(400).json({
|
||||
error: 'Invalid URL format',
|
||||
});
|
||||
}
|
||||
|
||||
// Parse skipCache (accept 'true', '1', 'yes', etc.)
|
||||
const shouldSkipCache = skipCache === 'true' || skipCache === '1' || skipCache === 'yes';
|
||||
|
||||
try {
|
||||
const metaData = await extractMetaTags(url, shouldSkipCache);
|
||||
res.json(metaData);
|
||||
} catch (error) {
|
||||
console.error('Meta tags extraction error:', error);
|
||||
res.status(500).json({
|
||||
status: 'error',
|
||||
url: url,
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user