var mapnik = require('mapnik');
var path = require('path');
var env = process.env.NODE_ENV || 'development';

var abilities = {
    carto: require('carto').tree.Reference.data,
    fonts: mapnik.fonts(),
    datasources: mapnik.datasources(),
    exports: {
        mbtiles: true,
        png: true,
        pdf: mapnik.supports.cairo
    }
};

server = Bones.Server.extend({});

server.prototype.initialize = function(app) {
    this.config = app.config;
    _(this).bindAll(
        'index',
        'abilities',
        'projectPoll',
        'projectFlush'
    );

    this.get('/', this.index);
    this.get('/assets/tilemill/js/abilities.js', this.abilities);

    // Custom Project sync endpoints.
    this.get('/api/Project/:id/:time(\\d+)', this.projectPoll);
    this.del('/api/Project/:id/:layer', this.projectFlush);

    // Add static provider to download exports.
    this.use('/export/download', middleware['static'](
        path.join(this.config.files, 'export'),
        { maxAge: env === 'production' ? 3600000 : 0 } // 1 hour
    ));
};

server.prototype.index = function(req, res, next) {
    res.send(templates['App']());
};

server.prototype.abilities = function(req, res, next) {
    var js = 'var abilities = ' + JSON.stringify(abilities) + ';';
    res.send(js, {'Content-type': 'text/javascript'});
};

server.prototype.projectPoll = function(req, res, next) {
    var model = new models.Project({
        id: req.param('id'),
        _updated: req.param('time')
    });
    model.sync('mtime', model, res.send.bind(res), next);
};

server.prototype.projectFlush = function(req, res, next) {
    var model = new models.Project(
        { id: req.param('id') },
        { layer: req.param('layer') }
    );
    model.sync('flush', model, res.send.bind(res), next);
};

@@ -694,24 +694,79 @@
  endpoints.%0A
+    this.get('/api/Project/:id.xml', this.projectXML);%0A
     this.get
@@ -1822,28 +1822,466 @@
 s.send.bind(res), next);%0A%7D;%0A
+%0Aserver.prototype.projectXML = function(req, res, next) %7B%0A    var model = new models.Project(%7B id: req.param('id') %7D);%0A    model.fetch(%7B%0A        success: function(model, resp) %7B%0A            model.localize(model.toJSON(), function(err) %7B%0A                if (err) return next(err);%0A                res.send(model.xml, %7B'content-type': 'text/xml'%7D);%0A            %7D);%0A        %7D,%0A        error: function(model, resp) %7B next(resp); %7D%0A    %7D);%0A%7D;%0A

Add project XML endpoint at /api/Project/[id].xml. Closes #505