(compiler, port, bindIp, longTermCaching, httpsOptions)
| 129 | // static compiled JavaScript. returns an object with two properties, started and stop; |
| 130 | // see the default function doc for explanation. |
| 131 | const startStaticJsServer = (compiler, port, bindIp, longTermCaching, httpsOptions) => { |
| 132 | const server = express(); |
| 133 | const httpServer = httpsOptions ? https.createServer(httpsOptions, server) : http.createServer(server); |
| 134 | return { |
| 135 | stop: serverToStopPromise(httpServer), |
| 136 | started: new Promise((resolve, reject) => { |
| 137 | compiler.run((err, stats) => { |
| 138 | const error = handleCompilationErrors(err, stats); |
| 139 | if (error) { |
| 140 | reject(error); |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | if (stats) { |
| 145 | logger.debug("Successfully compiled static JavaScript."); |
| 146 | } |
| 147 | |
| 148 | // TODO: make this parameterized based on what is returned from compileClient |
| 149 | server.use('/', compression(), express.static(`__clientTemp/build`, { |
| 150 | maxage: longTermCaching ? '365d' : '0s', |
| 151 | })); |
| 152 | logger.info("Starting static JavaScript server..."); |
| 153 | |
| 154 | httpServer.on('error', (e) => { |
| 155 | console.error("Error starting up JS server"); |
| 156 | console.error(e); |
| 157 | reject(e) |
| 158 | }); |
| 159 | httpServer.listen(port, bindIp, (e) => { |
| 160 | if (e) { |
| 161 | reject(e); |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | logger.info(`Started static JavaScript server over ${httpsOptions ? "HTTPS" : "HTTP"} on ${bindIp}:${port}`); |
| 166 | resolve(); |
| 167 | }); |
| 168 | }); |
| 169 | }), |
| 170 | }; |
| 171 | }; |
| 172 | |
| 173 | // given a webpack compiler and a port, start a webpack dev server that is ready |
| 174 | // for hot reloading at http://localhost:port/. note that the webpack compiler |
nothing calls this directly
no test coverage detected
searching dependent graphs…