Appium Server 源码分析 (二) - main 方法
来源:互联网 发布:以下哪种立体匹配算法 编辑:程序博客网 时间:2024/05/16 12:20
上一节 Appium Server 源码分析 (一) 中我们大体讲了,appium server在正确运行前做的一些判断,下来我们正式看看main 方法
在看main方法之前我们可以得看看main.js引用的那一大堆第三方的模块的主要作用是什么。
好了,下来正式看看我们的主角吧。
var nodeVer = Number(process.version.match(/^v(\d+\.\d+)/)[1]); if (nodeVer < 0.10) { logger.error("Appium requires Node >= 0.10"); process.exit(1); } if (nodeVer < 0.12) { logger.warn("Appium support for versions of node < 0.12 has been " + "deprecated and will be removed in a future version. Please " + "upgrade!"); }
判断nodejs的版本如果是小于0.10版本则直接退出,若小于0.12版本则给出相应的警告。
var rest = express() , server = http.createServer(rest); rest.use(domainMiddleware()); rest.use(morgan(function (tokens, req, res) { // morgan output is redirected straight to winston logger.info(requestEndLoggingFormat(tokens, req, res), (res.jsonResp || '').grey); })); rest.use(favicon(path.join(__dirname, 'static/favicon.ico'))); rest.use(express.static(path.join(__dirname, 'static'))); rest.use(allowCrossDomain); rest.use(parserWrap); rest.use(bodyParser.urlencoded({extended: true})); // 8/18/14: body-parser requires that we supply the limit field to ensure the server can // handle requests large enough for Appium's use cases. Neither Node nor HTTP spec defines a max // request size, so any hard-coded request-size limit is arbitrary. Units are in bytes (ie "gb" == "GB", // not "Gb"). Using 1GB because..., well because it's arbitrary and 1GB is sufficiently large for 99.99% // of testing scenarios while still providing an upperbounds to reduce the odds of squirrelliness. rest.use(bodyParser.json({limit: '1gb'})); rest.use(morgan(function (tokens, req, res) { // morgan output is redirected straight to winston var data = ''; try { if (req.body) data = JSON.stringify(req.body).substring(0, 1000); } catch (ign) {} logger.info(requestStartLoggingFormat(tokens, req, res), data.grey); }, {immediate: true})); rest.use(methodOverride()); // Instantiate the appium instance var appiumServer = appium(args); // Hook up REST http interface appiumServer.attachTo(rest); routing(appiumServer); rest.use(catchAllHandler);
创建express的http服务,并通过rest.use加载一系列的中间件,这些中间件的作用在前面的表格里其实已经大部分都说明了,并且在这中间件中还在夹带着初始化了一个appiumServer。实际上appiumServer就是一个附带着参数配置以及http服务的对象
async.series([ function (cb) { configureServer(getConfig(), appiumVer, appiumServer, function (err, rev) { if (err) return cb(err); appiumRev = rev; cb(); }); }, function (cb) { prepareTmpDir(args, cb); }, function (cb) { conditionallyPreLaunch(args, appiumServer, cb); }, function (cb) { startListening(server, args, parser, appiumVer, appiumRev, appiumServer, cb); } ], function (err) { if (err) { process.exit(1); } else if (typeof readyCb === "function") { readyCb(appiumServer); } }); server.on('close', function () { logFinalWarning(); doneCb(); });
最后是一系列的同步操作async.series
是顺序执行,最后添加close事件,关闭服务的时候,会调用设置好的回调函数。
0 0
- Appium Server 源码分析 (二) - main 方法
- Appium源码分析(2)-main函数
- Appium Server 源码分析(一)
- Appium Server 源码分析之启动运行Express http服务器
- Appium Server源码分析之作为Bootstrap客户端
- Appium Server 源码分析之启动运行Express http服务器
- Appium Server源码分析之作为Bootstrap客户端
- Appium Server源码分析之作为Bootstrap客户端
- Appium Server 源码分析 (三) - 路由及控制器
- Appium(7)appium server日志分析
- 魔兽世界服务器Trinitycore分析二:auth server的main函数
- appium Bootstrap UiSelectorParser源码分析
- ffmpeg源码分析二:main函数和transcode函数
- UiAutomator系列——Appium Server 源码分析之启动运行Express http服务器(010)
- UiAutomator系列——Appium Server源码分析之作为Bootstrap客户端(011)
- traffic server cache源码分析二 读写逻辑分析
- Appium Android Bootstrap源码分析之简介
- Appium源码项目的目录结构分析
- JAVA 学到什么水平就可以转战 Android 了?
- sparkPi源码解析
- 去掉tabbar上方的黑线
- 设置导航栏的背景颜色
- 2016GDOI总结
- Appium Server 源码分析 (二) - main 方法
- zoj-3735 Josephina and RPG[概率dp]
- Prime Independence(质因子分解+二分图最大独立集)
- Gson学习
- 基于Servlet3.0 comet http长连接
- getopts命令行参数处理
- 两个多项式相乘 使用散列表加速 在计算时合并多项式的项
- Android内核开发:从源码树中删除出厂的app应用
- Bluemix使用与其他云平台对比