mock_http_server.js 491 B

1234567891011121314151617
  1. 'use strict';
  2. const http = require('http');
  3. const SERVER = Symbol('http_server');
  4. module.exports = app => {
  5. let server = app[SERVER] || app.callback();
  6. if (typeof server === 'function') {
  7. server = http.createServer(server);
  8. // cache server, avoid create many times
  9. app[SERVER] = server;
  10. // emit server event just like egg-cluster does
  11. // https://github.com/eggjs/egg-cluster/blob/master/lib/app_worker.js#L52
  12. app.emit('server', server);
  13. }
  14. return server;
  15. };