Skip to content

Commit

Permalink
Merge pull request #2687 from sebv/express-4
Browse files Browse the repository at this point in the history
Migrated to express 4
  • Loading branch information
jlipps committed May 28, 2014
2 parents 9b0a0f6 + f535d41 commit 3c8b240
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 68 deletions.
4 changes: 1 addition & 3 deletions lib/appium.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

var routing = require('./server/routing.js')
, loggerjs = require('./server/logger.js')
var loggerjs = require('./server/logger.js')
, logger = loggerjs.get('appium')
, UUID = require('uuid-js')
, _ = require('underscore')
Expand Down Expand Up @@ -43,7 +42,6 @@ var Appium = function (args) {

Appium.prototype.attachTo = function (rest) {
this.rest = rest;
routing(this);
};

Appium.prototype.attachSocket = function (webSocket) {
Expand Down
50 changes: 26 additions & 24 deletions lib/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ if (

var http = require('http')
, express = require('express')
, favicon = require('serve-favicon')
, bodyParser = require('body-parser')
, methodOverride = require('method-override')
, morgan = require('morgan') // logger
, routing = require('./routing.js')
, path = require('path')
, appium = require('../appium.js')
, parserWrap = require('./middleware').parserWrap
Expand Down Expand Up @@ -73,37 +78,34 @@ var main = function (args, readyCb, doneCb) {
var rest = express()
, server = http.createServer(rest);

rest.configure(function () {
rest.use(express.favicon());
rest.use(express.static(path.join(__dirname, 'static')));
rest.use(allowCrossDomain);
if (!args.quiet) {
if (args.logNoColors) {
rest.use(express.logger(noColorLogger));
} else {
rest.use(express.logger('dev'));
}
rest.use(favicon(path.join(__dirname, 'static/favicon.ico')));
rest.use(express.static(path.join(__dirname, 'static')));
rest.use(allowCrossDomain);
if (!args.quiet) {
if (args.logNoColors) {
rest.use(morgan(noColorLogger));
} else {
rest.use(morgan('dev'));
}
if (args.log || args.webhook) {
rest.use(express.logger({stream: winstonStream}));
}
if (args.logNoColors || args.log) {
colors.mode = "none";
}
rest.use(parserWrap);
rest.use(express.urlencoded());
rest.use(express.json());
rest.use(express.methodOverride());
rest.use(rest.router);
rest.use(catchAllHandler);
});
}
if (args.log || args.webhook) {
rest.use(morgan({stream: winstonStream}));
}
if (args.logNoColors || args.log) {
colors.mode = "none";
}
rest.use(parserWrap);
rest.use(bodyParser.urlencoded());
rest.use(bodyParser.json());
rest.use(methodOverride());

// Instantiate the appium instance
var appiumServer = appium(args);

// Hook up REST http interface
appiumServer.attachTo(rest);

routing(appiumServer);
rest.use(catchAllHandler);

async.series([
function (cb) {
Expand Down
4 changes: 2 additions & 2 deletions lib/server/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports.shouldProxy = function (req) {
['POST', new RegExp('^/wd/hub/session$')]
, ['DELETE', new RegExp('^/wd/hub/session/[^/]+$')]
].concat(deviceAvoids);
var method = req.route.method.toUpperCase();
var method = req.method.toUpperCase();
var path = req.originalUrl;
var shouldAvoid = false;

Expand Down Expand Up @@ -54,7 +54,7 @@ module.exports.doProxy = function (req, res) {
}
var url = 'http://' + req.device.proxyHost + ':' + req.device.proxyPort +
newPath;
doRequest(url, req.route.method.toUpperCase(), req.body,
doRequest(url, req.method.toUpperCase(), req.body,
req.headers['content-type'], function (err, response, body) {
if (err) {
return respondError(req, res, status.codes.UnknownError.code,
Expand Down
74 changes: 39 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,56 @@
"doc": "./docs"
},
"dependencies": {
"underscore": "~1.6.0",
"adm-zip": "~0.4.3",
"appium-atoms": "~0.0.5",
"appium-instruments": "~0.1.21",
"appium-uiauto": "~0.0.18",
"argparse": "~0.1.15",
"async": "~0.9.0",
"binary-cookies": "~0.1.1",
"body-parser": "~1.2.0",
"bplist-creator": "~0.0.2",
"bplist-parser": "~0.0.4",
"bufferpack": "0.0.6",
"bytes": "~1.0.0",
"colors": "~0.6.2",
"express": "~3.5.1",
"date-utils": "~1.2.14",
"difflib": "~0.2.4",
"express": "~4.3.1",
"glob": "~4.0.0",
"grunt": "~0.4.1",
"grunt-cli": "~0.1.9",
"argparse": "~0.1.15",
"js2xmlparser2": "~0.2.0",
"md5calculator": "~0.0.3",
"method-override": "~1.0.2",
"mkdirp": "~0.5.0",
"morgan": "~1.1.1",
"mv": "~2.0.0",
"namp": "0.2.25",
"ncp": "~0.5.0",
"node-idevice": "~0.1.2",
"node-uuid": "~1.4.1",
"path": "~0.4.9",
"plist": "~0.4.3",
"prompt": "~0.2.11",
"request": "~2.36.0",
"rimraf": "~2.2.2",
"uuid-js": "~0.7.4",
"sandboxed-module": "~0.3.0",
"serve-favicon": "~2.0.0",
"socket.io": "~0.9.16",
"swig": "~1.3.2",
"temp": "~0.7.0",
"winston": "~0.7.2",
"request": "~2.36.0",
"bplist-parser": "~0.0.4",
"plist": "~0.4.3",
"bufferpack": "0.0.6",
"bplist-creator": "~0.0.2",
"node-uuid": "~1.4.1",
"through": "~2.3.4",
"underscore": "~1.6.0",
"underscore.string": "~2.3.3",
"glob": "~4.0.0",
"unzip": "~0.1.9",
"ncp": "~0.5.0",
"swig": "~1.3.2",
"async": "~0.9.0",
"mkdirp": "~0.5.0",
"xml2js": "~0.4.2",
"difflib": "~0.2.4",
"prompt": "~0.2.11",
"binary-cookies": "~0.1.1",
"namp": "0.2.25",
"node-idevice": "~0.1.2",
"uuid-js": "~0.7.4",
"win-spawn": "~2.0.0",
"adm-zip": "~0.4.3",
"winston": "~0.7.2",
"ws": "~0.4.31",
"socket.io": "~0.9.16",
"md5calculator": "~0.0.3",
"through": "~2.3.4",
"date-utils": "~1.2.14",
"bytes": "~1.0.0",
"appium-atoms": "~0.0.5",
"appium-instruments": "~0.1.21",
"appium-uiauto": "~0.0.18",
"mv": "~2.0.0",
"js2xmlparser2": "~0.2.0",
"xpath": "~0.0.6",
"xml2js": "~0.4.2",
"xmldom": "~0.1.19",
"sandboxed-module": "~0.3.0"
"xpath": "~0.0.6"
},
"scripts": {
"test": "grunt travis"
Expand Down
2 changes: 1 addition & 1 deletion test/functional/common/jsonwp-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("common - jsonwp @skip-ci @skip-ios6", function () {
it('should get 404 with text/plain body', function (done) {
request.get(serverUrl + '/a/bad/path', function (err, res, body) {
should.not.exist(err);
res.headers['content-type'].should.equal('text/plain');
res.headers['content-type'].should.equal('text/plain; charset=utf-8');
res.statusCode.should.equal(404);
body.should.be.ok;
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var env = require('../../helpers/env')
describe('app activities - fully qualified', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
var session;
var name = this.parent.title + " " + this.title;
var name = this.title;

afterEach(function (done) {
session
Expand Down
2 changes: 1 addition & 1 deletion test/functional/selendroid/app-act-no-dot-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var env = require('../../helpers/env')
describe('app activities - with no dot', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
var session;
var name = this.parent.title + " " + this.title;
var name = this.title;
it('should not launch app', function (done) {
var newDesired = _.defaults({'appActivity': 'ApiDemos'}, desired);
session = initSession(newDesired, {'no-retry': true, 'expect-error': true});
Expand Down
1 change: 0 additions & 1 deletion test/unit/routing-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var rest = require('express')()

describe('Appium', function () {
var inst = appium({});
rest.use(rest.router);

describe('#attachTo', function () {
return it('should get valid routes', function (done) {
Expand Down

0 comments on commit 3c8b240

Please sign in to comment.