SHARE
TWEET

Untitled

a guest Jan 18th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Dependencies
  2. const fs = require('fs');
  3. const http = require('http');
  4. const https = require('https');
  5. const express = require('express');
  6.  
  7. const app = express();
  8.  
  9. // Certificate
  10. const privateKey = fs.readFileSync('/etc/letsencrypt/live/mi-dominio.com/privkey.pem', 'utf8');
  11. const certificate = fs.readFileSync('/etc/letsencrypt/live/mi-dominio.com/cert.pem', 'utf8');
  12. const ca = fs.readFileSync('/etc/letsencrypt/live/mi-dominio.com/chain.pem', 'utf8');
  13.  
  14. const credentials = {
  15.     key: privateKey,
  16.     cert: certificate,
  17.     ca: ca
  18. };
  19.  
  20. app.use((req, res) => {
  21.     res.send('Hello there !');
  22. });
  23.  
  24. // Starting both http & https servers
  25. const httpServer = http.createServer(app);
  26. const httpsServer = https.createServer(credentials, app);
  27.  
  28. httpServer.listen(80, () => {
  29.     console.log('HTTP Server running on port 80');
  30. });
  31.  
  32. httpsServer.listen(443, () => {
  33.     console.log('HTTPS Server running on port 443');
  34. });
  35.    
  36. events.js:141
  37.       throw er; // Unhandled 'error' event
  38.       ^
  39.  
  40. Error: listen EACCES 0.0.0.0:80
  41.     at Object.exports._errnoException (util.js:870:11)
  42.     at exports._exceptionWithHostPort (util.js:893:20)
  43.     at Server._listen2 (net.js:1221:19)
  44.     at listen (net.js:1270:10)
  45.     at Server.listen (net.js:1366:5)
  46.     at Object.<anonymous> (/home/ec2-user/index.js:28:12)
  47.     at Module._compile (module.js:409:26)
  48.     at Object.Module._extensions..js (module.js:416:10)
  49.     at Module.load (module.js:343:32)
  50.     at Function.Module._load (module.js:300:12)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top