MCPcopy
hub / github.com/ampproject/amphtml / startServer

Function startServer

build-system/tasks/serve.js:96–154  ·  view source on GitHub ↗

* Launches a server and waits for it to fully start up * * @param {?Object} connectOptions * @param {?Object} serverOptions * @param {?Object} modeOptions * @return {Promise }

(
  connectOptions = {},
  serverOptions = {},
  modeOptions = {}
)

Source from the content-addressed store, hash-verified

94 * @return {Promise<void>}
95 */
96async function startServer(
97 connectOptions = {},
98 serverOptions = {},
99 modeOptions = {}
100) {
101 await buildNewServer();
102 if (serverOptions.lazyBuild) {
103 lazyBuild = serverOptions.lazyBuild;
104 }
105 if (serverOptions.quiet) {
106 quiet = serverOptions.quiet;
107 }
108
109 let started;
110 const startedPromise = new Promise((resolve) => {
111 started = resolve;
112 });
113 setServeMode(modeOptions);
114
115 /** @type {GulpConnectOptionsDef} */
116 const options = {
117 name: 'AMP Dev Server',
118 root: process.cwd(),
119 host: HOST,
120 port: PORT,
121 https: argv.https,
122 preferHttp1: true,
123 silent: true,
124 middleware: getMiddleware,
125 ...connectOptions,
126 };
127 connect.server(options, started);
128 await startedPromise;
129
130 /**
131 * @param {string} host
132 * @return {string}
133 */
134 function makeUrl(host) {
135 return `http${options.https ? 's' : ''}://${host}:${options.port}`;
136 }
137
138 url = makeUrl(options.host);
139 log(green('Started'), cyan(options.name), green('at:'));
140 log('\t', cyan(url));
141 for (const device of Object.entries(os.networkInterfaces())) {
142 for (const detail of device[1] ?? []) {
143 if (detail.family === 'IPv4') {
144 log('\t', cyan(makeUrl(detail.address)));
145 }
146 }
147 }
148 if (argv.coverage == 'live') {
149 const covUrl = `${url}/coverage`;
150 log(green('Collecting live code coverage at'), cyan(covUrl));
151 await Promise.all([open(covUrl), open(url)]);
152 }
153 logServeMode();

Callers 5

restartServerFunction · 0.85
doServeFunction · 0.85
performVisualTestsFunction · 0.85
setUpTesting_Function · 0.85
setupMethod · 0.85

Calls 9

buildNewServerFunction · 0.85
makeUrlFunction · 0.85
greenFunction · 0.85
cyanFunction · 0.85
openFunction · 0.85
logServeModeFunction · 0.85
setServeModeFunction · 0.50
logFunction · 0.50
entriesMethod · 0.45

Tested by

no test coverage detected