NodeJS: Delivering a crossdomain.xml file using Express.JS


/ Published in: JavaScript
Save to your folder(s)

There are many ways to deliver a crossdomain.xml file through NodeJS or Express.js. Here is one solution


Copy this code and paste it in your HTML
  1. app.get( "/crossdomain.xml", onCrossDomainHandler )
  2. function onCrossDomainHandler( req, res ) {
  3. var xml = '<?xml version="1.0"?>\n<!DOCTYPE cross-domain-policy SYSTEM' +
  4. ' "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">\n<cross-domain-policy>\n';
  5. xml += '<allow-access-from domain="*" to-ports="*"/>\n';
  6. xml += '</cross-domain-policy>\n';
  7.  
  8. req.setEncoding('utf8');
  9. res.writeHead( 200, {'Content-Type': 'text/xml'} );
  10. res.end( xml );
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.