MCPcopy
hub / github.com/microsoft/playwright / start

Method start

packages/utils/httpServer.ts:150–178  ·  view source on GitHub ↗
(options: { port?: number, preferredPort?: number, host?: string } = {})

Source from the content-addressed store, hash-verified

148 }
149
150 async start(options: { port?: number, preferredPort?: number, host?: string } = {}): Promise<void> {
151 assert(!this._started, 'server already started');
152 this._started = true;
153
154 const host = options.host;
155 if (options.preferredPort) {
156 try {
157 await startHttpServer(this._server, { port: options.preferredPort, host });
158 } catch (e) {
159 if (!e || !e.message || !e.message.includes('EADDRINUSE'))
160 throw e;
161 await startHttpServer(this._server, { host });
162 }
163 } else {
164 await startHttpServer(this._server, { port: options.port, host });
165 }
166
167 const address = this._server.address();
168 assert(address, 'Could not bind server socket');
169 if (typeof address === 'string') {
170 this._urlPrefixPrecise = address;
171 this._urlPrefixHumanReadable = address;
172 } else {
173 this._port = address.port;
174 this._urlPrefixPrecise = `http://${urlHostFromAddress(address)}:${address.port}`;
175 this._urlPrefixHumanReadable = `http://${host ?? 'localhost'}:${address.port}`;
176 this._allowedHosts = computeAllowedHosts(host, address.address);
177 }
178 }
179
180 async stop() {
181 await new Promise(cb => this._server!.close(cb));

Callers 3

serveTraceSnapshotFunction · 0.95
startDashboardServerFunction · 0.95
startTraceViewerServerFunction · 0.95

Calls 4

assertFunction · 0.90
startHttpServerFunction · 0.90
urlHostFromAddressFunction · 0.85
computeAllowedHostsFunction · 0.85

Tested by

no test coverage detected