in src/server/server.js [67:130]
SimulationServer.prototype.start = function (platform, opts) {
var config = this._simulatorProxy.config;
this._cordovaServer = cordovaServe();
/* attach simulation host middleware */
var middlewarePath = path.join(config.simHostOptions.simHostRoot, 'server', 'server.js');
var simHostMiddleware = null;
if (fs.existsSync(middlewarePath)) {
simHostMiddleware = require(middlewarePath);
simHostMiddleware.attach(this._cordovaServer.app, dirs, this._hostRoot);
}
/* attach custom middleware */
if (this._config.middleware) {
var customiddlewarePath = path.join(process.cwd(), this._config.middleware);
if (!fs.existsSync(customiddlewarePath)) {
throw new Error('middleware could not be found');
}
this._cordovaServer.app.use(require('body-parser').json());
this._cordovaServer.app.use(require(customiddlewarePath));
}
/* attach CORS proxy middleware */
if (config.xhrProxy) {
require('./xhr-proxy').attach(this._cordovaServer.app);
}
this._prepareRoutes(simHostMiddleware);
var serverOpts = {
port: opts.port,
root: opts.dir,
noServerInfo: true
};
if (this._config.middleware) {
serverOpts.middleware = this._config.middleware;
}
return this._cordovaServer.servePlatform(platform, serverOpts)
.then(function () {
this._trackServerConnections();
this._simSocket.init(this._cordovaServer.server);
// setup simulation URLs
var projectRoot = this._cordovaServer.projectRoot,
urlRoot = 'http://localhost:' + this._cordovaServer.port + '/';
this._urls = {
root: urlRoot,
app: urlRoot + parseStartPage(projectRoot),
simHost: urlRoot + 'simulator/index.html'
};
log.log('Server started:\n- App running at: ' + this._urls.app + '\n- Sim host running at: ' + this._urls.simHost);
return {
urls: this._urls,
projectRoot: projectRoot,
root: this._cordovaServer.root
};
}.bind(this));
};