www 907 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env node
  2. 'use strict';
  3. require('babel/register');
  4. const app = require('../app');
  5. const io = require('../io').io;
  6. const debug = require('debug')('reti-chess:server');
  7. const port = process.env.PORT || '8181';
  8. const ip = process.env.IP || '127.0.0.1';
  9. app.set('ip', ip);
  10. app.set('port', port);
  11. const server = app.listen(app.get('port'), () => {
  12. debug('Express server listening on port ' + server.address().port);
  13. });
  14. server.on('error', error => {
  15. if (error.syscall !== 'listen') {
  16. throw error;
  17. }
  18. const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
  19. switch (error.code) {
  20. case 'EACCES':
  21. console.error(bind + ' requires elevated privileges');
  22. process.exit(1);
  23. break;
  24. case 'EADDRINUSE':
  25. console.error(bind + ' is already in use');
  26. process.exit(1);
  27. break;
  28. default:
  29. throw error;
  30. }
  31. });
  32. io.attach(server);