Files
appium/test/protocol/helpers.js
T
Dan Graham 97c02c8af0 Rename 'mjsonwp' to 'protocol' (#178)
* Rename 'mjsonwp' to 'protocol'
  * Renamed folder from 'mjsonwp' to 'protocol' in `lib/` and `test/`
  * Renamed 'mjsonwp.js' to 'protocol.js'
  * Renamed any import statements that use 'mjsonwp'
  * _Possible breaking change_: MJSONWireProtocol class exposed in index was renamed to just Protocol.... checked Appium repo and found no libraries that use MJSONWireProtocol
* Lint fix
2018-01-29 12:41:14 -08:00

25 lines
594 B
JavaScript

import Express from 'express';
import bodyParser from 'body-parser';
export function createProxyServer (sessionId, port) {
// Start an express server for proxying
let app = new Express();
app.use(bodyParser.json());
let server = app.listen(port);
return {app, server};
}
let handlers = {
post: {},
get: {},
delete: {},
put: {},
};
export function addHandler (app, method, url, handler) {
method = method.toLowerCase();
if (!handlers[method][url]) {
app[method](url, (req, res) => handlers[method][url].call(this, req, res));
}
handlers[method][url] = handler;
}