Closed UmbraLimi closed 8 years ago
hey man did you ever figure this out? I'm curious too... real curious
I did and I will try to post it here tomorrow. I ended up using picker as it caught the routing on the server.
nice seems like that'll work for me too
I'm pasting from a Windows text editor so the formatting is a mess - apologies.
Hope it helps. This was from a site built with Meteor v1.2.1
Meteor.startup(function() { Picker.route('/sitemap.xml', function(params, req, res, next) { res.writeHead(200, {'Content-Type': 'application/xml'}); res.end(Sitemaps.stream_sitemap()); });
Picker.route('/robots.txt', function(params, req, res, next) { res.writeHead(200, {'Content-Type': 'text/plain'}); // or 'text/html' res.end(Sitemaps.stream_robots_txt()); });
Picker.route('/BingSiteAuth.xml', function(params, req, res, next) { res.writeHead(200, {'Content-Type': 'application/xml'}); res.end(Sitemaps.stream_bingsiteauth()); }); }
Sitemaps = function() {
var _init = function() {
};
let _assemble_sitemap_string = function() { let URL_Prefix = React_Helpers.get_misc_value("URL-Prefix", "utilities.js"); let links = [];
links.push('<?xml version="1.0" encoding="UTF-8"?>');
links.push('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
let cursor;
// Programs
cursor = Programs.find({});
cursor.forEach(function(record) {
links.push("<url>");
links.push(" <loc>" + URL_Prefix + record.route + "</loc>");
links.push(" <lastmod>" + moment(record.updated_on).format() + "</lastmod>");
links.push(" <changefreq>" + "weekly" + "</changefreq>");
links.push(" <priority>" + "0.8" + "</priority>");
links.push("</url>");
}, this)
links.push("</urlset>");
return links.join("\r\n");
};
let _assemble_robots_txt_string = function() { let rows = []; rows.push("sitemap: http://zzzzzzzzzzzzzzz.com/sitemap.xml"); rows.push("User-agent: *"); rows.push("Disallow: /alm/"); return rows.join("\r\n"); };
let _assemble_bingsiteauth_string = function() {
let rows = [];
rows.push('<?xml version="1.0" encoding="UTF-8"?>'); // may not need the encoding
rows.push('
let _write_sitemap = function() { console.log("|-- creating /sitemap.xml file"); let fs = Npm.require('fs'); let smap = _assemble_sitemap_string();
fs.writeFileSync("/sitemap.xml", smap, 'utf8');
console.log("|-- finished /sitemap.xml file");
};
let _stream_bingsiteauth = function() { return _assemble_bingsiteauth_string(); };
let _stream_sitemap = function() { return _assemble_sitemap_string(); }; let _stream_robots_txt = function() { return _assemble_robots_txt_string(); }; // ----------------------------------------------------------------- return { // these are the public methods of Misc init: function() { },
write_sitemap: function() {
return _write_sitemap();
},
stream_sitemap: function() {
return _stream_sitemap();
},
stream_robots_txt: function() {
return _stream_robots_txt();
},
stream_bingsiteauth: function() {
return _stream_bingsiteauth();
},
}
}();
I'd like to dynamically generate (without creating a file at all) a sitemap with the following:
Is this a valid route? Can you "return" the content you want this way?
I am using FlowRouter SSR at the moment.
Thanks in advance for any help/suggestions :)