Automatically migrated from Gitolite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.2 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. #!/usr/bin/env coffee
  2. app = require('../app')
  3. debug = require('debug')('pdfy:server')
  4. http = require('http')
  5. https = require("https")
  6. config = require "../config.json"
  7. fs = require "fs"
  8. normalizePort = (val) ->
  9. port = parseInt val, 10
  10. if isNaN port
  11. return val
  12. if port >= 0
  13. return port
  14. return false
  15. onError = (error) ->
  16. if error.syscall != "listen"
  17. throw error
  18. bind = if typeof port == "string"
  19. "Pipe #{port}"
  20. else
  21. "Port #{port}"
  22. switch error.code
  23. when "EACCES"
  24. console.error "#{bind} requires elevated privileges"
  25. process.exit 1
  26. when "EADDRINUSE"
  27. console.error "#{bind} is already in use"
  28. process.exit 1
  29. else
  30. throw error
  31. onListening = ->
  32. addr = httpServer.address()
  33. bind = if typeof port == "string"
  34. "pipe #{port}"
  35. else
  36. "port #{port}"
  37. debug("Listening on #{bind}")
  38. port = normalizePort(process.env.PORT || '3000')
  39. app.set('port', port)
  40. httpServer = http.createServer(app)
  41. httpServer.listen(port)
  42. httpServer.on('error', onError)
  43. httpServer.on('listening', onListening)
  44. if config.ssl?.key?
  45. credentials = {key: fs.readFileSync(config.ssl.key)}
  46. if config.ssl.cert?
  47. credentials.cert = fs.readFileSync(config.ssl.cert)
  48. if config.ssl.ca?
  49. credentials.ca = fs.readFileSync(config.ssl.ca)
  50. if config.ssl.ciphers?
  51. credentials.ciphers = config.ssl.ciphers
  52. else
  53. credentials.ciphers = "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA"
  54. httpsServer = https.createServer(credentials, app)
  55. httpsServer.listen(443)
  56. httpsServer.on('error', onError)
  57. httpsServer.on('listening', onListening)