Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express=require('express');
- var bodyParser=require('body-parser');
- var https=require('https');
- var http=require('http');
- var path=require('path');
- var url=require('url');
- var fs=require('fs');
- var httpsRedirect = require('express-https-redirect');
- // This line is from the Node.js HTTPS documentation.
- var options = {
- key: fs.readFileSync('private.key'),
- cert: fs.readFileSync('certificate.pem')
- };
- // Create a service (the app object is just a callback).
- var app = express();
- app.use('/', httpsRedirect(true))
- // Create an HTTP service.
- http.createServer(app).listen(80);
- // Create an HTTPS service identical to the HTTP service.
- https.createServer(options, app).listen(443);
- app.set('static',path.join(__dirname,'static'));
- app.set('view engine','ejs');
- app.set('views',path.join(__dirname,'views'));
- app.use(bodyParser.json());
- app.use(bodyParser.urlencoded({extended:false}));
- app.get('/',function(req,res){
- //login form
- res.render('index.ejs');
- });
- app.post('/home',function(req,res){
- if(req.body.username=="mazen"&&req.body.password=="mark"){
- res.render('homee.ejs');}
- else{
- res.render('error.ejs');
- }
- });
- //I figured out that on my local computer,
- //the EACCES error is coming because I have to run node as root in order to bind to those certain ports.
- //I don't know why this happens, but using sudo fixes it.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement