Now I have this code to create sitemap.xml when I run /sitemap.xml
database = firebase.database();
var ref = database.ref('urls');
ref.on('value', gotData, errData);
function errData(err){
console.log('Error!');
console.log(err);
}
function gotData(data){
result = data.val()
return urls = Object.keys(result)
.filter(key => result[key].last_res > 5)
.map(key => ({url: '/' + result[key].url_site + '/'}))
}
when i try running console.log(urls) in gotData(data) function, it returns as
{ salmon:
{ count: 1,
last_res: 10,
url_site: 'salmon' },
'salmon-food':
{ count: 1,
last_res: 601,
url_site: 'salmon-food' } }
I need to return 'urls' in gotData(data) to create sitemap.xml.
var sitemap = sm.createSitemap({
hostname: 'xxx.com',
cacheTime: 600000,
urls: urls
});
app.get('/sitemap.xml', function(req, res) {
sitemap.toXML( function (err, xml) {
if (err) {
return res.status(500).end();
}
res.header('Content-Type', 'application/xml');
res.send( xml );
});
});
}
But now its error on var = sitemap as
urls: urls -> urls is not defined
So how can I fix it?
via Moomoo Soso
No comments:
Post a Comment