* 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 = {}
)
| 94 | * @return {Promise<void>} |
| 95 | */ |
| 96 | async 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(); |
no test coverage detected