mirror of
https://github.com/appium/appium.git
synced 2026-10-25 18:21:19 +08:00
The webdriver spec specifies that requests where the method is POST should be parsed as JSON (see https://www.w3.org/TR/webdriver/#processing-model step 6). Appium is too restrictive. It only parses as JSON if the application/json Content-Type is provided, making it incompatible with some Webdriver clients that follow the spec but don't send a Content-Type header. This commit makes Appium less restrictive by defaulting to the application/json Content-Type if none is provided.
appium-express
Express server tuned for to serve Appium.
Configuration
The appium-express server comes configured with:
- appropriate logging formats
- service of necessary static assets
- allowance of cross-domain requests
- default error handling
- fix for invalid content types sent by certain clients
To configure routes, a function that takes an Express server is passed into the server. This function can add whatever routes are wanted.
Usage
import { server } from 'appium-base-driver';
// configure the routes
function configureRoutes (app) {
app.get('/hello', (req, res) => {
res.header['content-type'] = 'text/html';
res.status(200).send('Hello');
});
app.get('/world', (req, res) => {
res.header['content-type'] = 'text/html';
res.status(200).send('World');
});
}
let port = 5000;
let host = 'localhost';
let appiumServer = await server(configureRoutes, port, host);
Watch
npm run watch
Test
npm test