MCPcopy Create free account
hub / github.com/appium/appium / createServer

Function createServer

packages/http-server/lib/server.ts:256–279  ·  view source on GitHub ↗
(app: Express, cliArgs?: Partial<ServerArgs>)

Source from the content-addressed store, hash-verified

254}
255
256async function createServer(app: Express, cliArgs?: Partial<ServerArgs>): Promise<HttpServer> {
257 const {sslCertificatePath, sslKeyPath} = cliArgs ?? {};
258 if (!sslCertificatePath && !sslKeyPath) {
259 return http.createServer(app);
260 }
261 if (!sslCertificatePath || !sslKeyPath) {
262 throw new Error(`Both certificate path and key path must be provided to enable TLS`);
263 }
264
265 const certKey = [sslCertificatePath, sslKeyPath];
266 const [certExists, keyExists] = await Promise.all(certKey.map((p) => fs.exists(p)));
267 for (const [exists, desc, p] of [
268 [certExists, 'certificate', sslCertificatePath],
269 [keyExists, 'key', sslKeyPath],
270 ]) {
271 if (!exists) {
272 throw new Error(`The provided SSL ${desc} at '${p}' does not exist or is not accessible`);
273 }
274 }
275 const [cert, key] = (await Promise.all(certKey.map((p) => fs.readFile(p, 'utf8')))) as [string, string];
276 log.debug('Enabling TLS on the server using the provided certificate');
277
278 return https.createServer({cert, key}, app) as unknown as HttpServer;
279}
280
281/**
282 * Attaches Appium-specific behavior to the HTTP server and returns it as {@linkcode AppiumServer}.

Callers 3

serverFunction · 0.70
plugin.spec.tsFile · 0.50
listenOnAnyPortFunction · 0.50

Calls 3

allMethod · 0.80
existsMethod · 0.80
debugMethod · 0.65

Tested by

no test coverage detected