Advertisement
Guest User

Untitled

a guest
Oct 29th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express=require('express');
  2. var bodyParser=require('body-parser');
  3. var https=require('https');
  4. var http=require('http');
  5. var path=require('path');
  6. var url=require('url');
  7. var fs=require('fs');
  8. var httpsRedirect = require('express-https-redirect');
  9. // This line is from the Node.js HTTPS documentation.
  10. var options = {
  11.     key: fs.readFileSync('private.key'),
  12.     cert: fs.readFileSync('certificate.pem')
  13.   };
  14.  // Create a service (the app object is just a callback).
  15. var app = express();
  16. app.use('/', httpsRedirect(true))
  17.  
  18. // Create an HTTP service.
  19. http.createServer(app).listen(80);
  20. // Create an HTTPS service identical to the HTTP service.
  21. https.createServer(options, app).listen(443);
  22.  
  23.  
  24. app.set('static',path.join(__dirname,'static'));
  25. app.set('view engine','ejs');
  26. app.set('views',path.join(__dirname,'views'));
  27. app.use(bodyParser.json());
  28. app.use(bodyParser.urlencoded({extended:false}));
  29. app.get('/',function(req,res){
  30. //login form
  31.     res.render('index.ejs');
  32.  
  33. });
  34.  
  35. app.post('/home',function(req,res){
  36.     if(req.body.username=="mazen"&&req.body.password=="mark"){
  37.     res.render('homee.ejs');}
  38.     else{
  39.     res.render('error.ejs');   
  40.     }
  41.  
  42.  
  43. });
  44.  
  45. //I figured out that on my local computer,
  46. //the EACCES error is coming because I have to run node as root in order to bind to those certain ports.
  47. //I don't know why this happens, but using sudo fixes it.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement