forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathserver.js
59 lines (54 loc) · 1.7 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";
var http = require('http')
, express = require('express')
, path = require('path')
, logger = require('./logger').get('appium')
, appium = require('./app/appium')
, parser = require('./app/parser');
var main = function(args, readyCb, doneCb) {
var rest = express()
, server = http.createServer(rest);
if (typeof doneCb === "undefined") {
doneCb = function() {};
}
// in case we'll support blackberry at some point
args.device = 'iOS';
rest.configure(function() {
var bodyParser = express.bodyParser()
, parserWrap = function(req, res, next) {
// wd.js sends us http POSTs with empty body which will make bodyParser fail.
if (parseInt(req.get('content-length'), 10) <= 0) {
return next();
}
bodyParser(req, res, next);
};
rest.use(express.favicon());
rest.use(express.static(path.join(__dirname, '/app/static')));
if (args.verbose) {
rest.use(express.logger('dev'));
}
rest.use(parserWrap);
rest.use(express.methodOverride());
rest.use(rest.router);
});
// Instantiate the appium instance
var appiumServer = appium(args);
// Hook up REST http interface
appiumServer.attachTo(rest);
// Start the web server that receives all the commands
server.listen(args.port, args.address, function() {
var logMessage = "Appium REST http interface listener started on "+args.address+":"+args.port;
logger.info(logMessage.cyan);
if (readyCb) {
readyCb(appiumServer);
}
});
server.on('close', doneCb);
return server;
};
if (require.main === module) {
// Parse the command line arguments
var args = parser().parseArgs();
main(args);
}
module.exports.run = main;