Permalink
Browse files

Added an XDR port to yogi serve

  • Loading branch information...
1 parent 9f110fb commit f99513a73c76d901e8975c1bbb9337fdb5c05434 @davglass davglass committed Dec 18, 2012
Showing with 58 additions and 25 deletions.
  1. +58 −25 lib/cmds/serve.js
View
@@ -477,21 +477,25 @@ mods = {
});
});
},
- toSeed: function(str) {
+ toSeed: function(str, fixGallery) {
+ if (fixGallery) {
+ str += "\n";
+ str += "YUI.applyConfig({\n";
+ str += " groups: {\n";
+ str += " gallery: {\n";
+ str += " combine: false,\n";
+ str += " root: '/build/',\n";
+ str += " patterns: {\n";
+ str += " 'gallery-': { },\n";
+ str += " 'lang/gallery-': {},\n";
+ str += " 'gallerycss-': { type: 'css' }\n";
+ str += " }\n";
+ str += " }\n";
+ str += " }\n";
+ str += "});\n";
+ }
str += "\n";
- str += "YUI.applyConfig({\n";
- str += " groups: {\n";
- str += " gallery: {\n";
- str += " combine: false,\n";
- str += " root: '/build/',\n";
- str += " patterns: {\n";
- str += " 'gallery-': { },\n";
- str += " 'lang/gallery-': {},\n";
- str += " 'gallerycss-': { type: 'css' }\n";
- str += " }\n";
- str += " }\n";
- str += " }\n";
- str += "});\n";
+ str += 'var YOGI_CONFIG = ' + JSON.stringify(this.getConfig(), null, 4) + ';';
str += "\n";
return str;
},
@@ -548,9 +552,7 @@ mods = {
res.charset = 'utf-8';
res.contentType(file);
if (file.indexOf('build' + path.sep + 'yui') > -1) {
- if (!util.isYUI()) {
- data = self.toSeed(data);
- }
+ data = self.toSeed(data, !util.isYUI());
}
res.send(data);
}
@@ -713,8 +715,28 @@ mods = {
res.send('Not Found', 404);
}
});
-
- callback();
+
+ self.attachXDR(function() {
+ callback();
+ });
+ },
+ attachXDR: function(callback) {
+ var self = this;
+ portfinder.getPort(function(err, port) {
+ log.info('launching xdr server on port ' + port);
+ var server = express.createServer(),
+ handle = function(req, res) {
+ ee.serve(req, res);
+ };
+ server.use(express.bodyParser());
+ server.get('*', handle);
+ server.post('*', handle);
+ server['delete']('*', handle);
+ server.listen(port);
+ self.xdrPort = port;
+ self.xdr = server;
+ callback();
+ });
},
run: function () {
var self = this;
@@ -740,6 +762,21 @@ mods = {
this.app.closed = true;
}
}
+ try {
+ this.xdr.close();
+ } catch (e) {}
+ },
+ getConfig: function() {
+ var config = {
+ version: version,
+ yui: util.isYUI(),
+ module: this.module
+ };
+
+ if (this.xdrPort) {
+ config.xdrPort = this.xdrPort;
+ }
+ return config;
},
startServer: function() {
var name = this.module.name,
@@ -767,15 +804,10 @@ mods = {
this.app.listen(port);
this.app.get('/', function(req, res) {
- var YOGI_CONFIG = {
- version: version,
- yui: util.isYUI(),
- module: self.module
- };
index = fs.readFileSync(path.join(__dirname, '../../web/index.html'), 'utf8'),
index = index.replace(/\{\{module\}\}/gi, self.module.name);
- index = index.replace('{{YOGI_CONFIG}}', JSON.stringify(YOGI_CONFIG, null, 4));
+ index = index.replace('{{YOGI_CONFIG}}', JSON.stringify(self.getConfig(), null, 4));
res.header('Yogi-Served', 'Yes');
fs.readdir(testDir, function(err, files) {
var base = path.join(git.findRoot(), '../src'),
@@ -896,6 +928,7 @@ mods = {
this.yeti(stack.add(noop));
}
this.tests(stack.add(noop));
+
stack.done(function() {
if (self.options.parsed.port && self.options.parsed.port !== port) {
log.warn('It appears that port ' + self.options.parsed.port + ' was in use, so I picked ' + port + ' for you');

0 comments on commit f99513a

Please sign in to comment.