()
| 206 | } |
| 207 | |
| 208 | async startHttpServer() { |
| 209 | this.app = this.express(); |
| 210 | const compression = require('compression'); |
| 211 | this.app.use( |
| 212 | compression({ |
| 213 | filter(req, res) { |
| 214 | let type = res.getHeader('Content-Type'); |
| 215 | |
| 216 | if (res.getHeader('x-no-compression')) { |
| 217 | // don't compress responses with this response header |
| 218 | return false; |
| 219 | } else if (type && type.indexOf('text/event-stream') > -1) { |
| 220 | // don't attempt to compress server sent events |
| 221 | return false; |
| 222 | } else { |
| 223 | return compression.filter(req, res); |
| 224 | } |
| 225 | }, |
| 226 | }) |
| 227 | ); |
| 228 | |
| 229 | this.setupHttpServer(); |
| 230 | |
| 231 | let options = this.startOptions; |
| 232 | options.httpServer = this.httpServer; |
| 233 | let liveReloadServer; |
| 234 | |
| 235 | if (options.path) { |
| 236 | liveReloadServer = { |
| 237 | setupMiddleware() {}, |
| 238 | }; |
| 239 | } else { |
| 240 | liveReloadServer = new LiveReloadServer({ |
| 241 | app: this.app, |
| 242 | ui: options.ui, |
| 243 | watcher: options.watcher, |
| 244 | project: options.project, |
| 245 | httpServer: options.httpServer, |
| 246 | }); |
| 247 | } |
| 248 | |
| 249 | const config = this.project.config(options.environment); |
| 250 | const middlewareOptions = Object.assign({}, options, { |
| 251 | rootURL: config.rootURL, |
| 252 | }); |
| 253 | |
| 254 | await liveReloadServer.setupMiddleware(this.startOptions); |
| 255 | await this.processAppMiddlewares(middlewareOptions); |
| 256 | await this.processAddonMiddlewares(middlewareOptions); |
| 257 | |
| 258 | return this.listen(options.port, options.host).catch(() => { |
| 259 | throw new SilentError( |
| 260 | `Could not serve on http://${this.displayHost(options.host)}:${options.port}. ` + |
| 261 | `It is either in use or you do not have permission.` |
| 262 | ); |
| 263 | }); |
| 264 | } |
| 265 |
no test coverage detected