Skip to content

Instantly share code, notes, and snippets.

@dileephell
Created February 22, 2018 13:49
Show Gist options
  • Select an option

  • Save dileephell/acb234e8265a1ca4ceadc0d4469f9019 to your computer and use it in GitHub Desktop.

Select an option

Save dileephell/acb234e8265a1ca4ceadc0d4469f9019 to your computer and use it in GitHub Desktop.
var express = require('express');
var session = require('express-session');
var bodyParser = require('body-parser');
var app = express();
var path = require('path');
var cors = require('cors');
app.use(cors());
// app.all('*', function(req, res, next){
// //origin = req.get('Origin') || '*';
// res.set('Access-Control-Allow-Origin', 'https://localahost:3000/admin');
// res.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
// res.set('Access-Control-Expose-Headers', 'Content-Length');
// res.set('Access-Control-Allow-Credentials', 'true');
// res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type'); // add the list of headers your site allows.
// if ('OPTIONS' == req.method) return res.send(200);
// next();
// });
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({secret: 'ssshhhhh',saveUninitialized: true,resave: true}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
var sess;
app.get('/',function(req,res){
sess=req.session;
if(sess.username)
{
res.redirect('/admin');
}
else{
res.render('index.html');
}
});
app.post('/login',function(req,res){
sess=req.session;
sess.username=req.body.username;
res.end('done');
});
app.get('/admin',function(req,res){
sess=req.session;
//if(sess.username)
// {
// //res.sendFile(path.join(__dirname + '/sendFile.html'));
// res.write('<h1>Hello '+sess.username+', Welcome to .How can I help you?<i class="fa fa-microphone" style="font-size:50px"></i></h1><br></br><h2>Drag and drop any file to start a new data flow.</h2><br>Did my Benefits data come through last night?</br><br> Whats ths status of my payroll feed to T&A?</br> <br>How many new hires were processed last week</br>');
// res.end('<a href='+'/logout'+'>Logout</a>');
// }
// else
// {
// res.write('<h1>Please login first.</h1>');
// res.end('<a href='+'/'+'>Login</a>');
// }
var filePath = "./public/sendFile.html"
var resolvedPath = path.resolve(filePath);
console.log(resolvedPath);
return res.sendFile(resolvedPath);
});
app.get('/logout',function(req,res){
req.session.destroy(function(err){
if(err){
console.log(err);
}
else
{
res.redirect('/');
}
});
});
app.listen(3000,function(){
console.log("App Started on PORT 3000");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment