var app = require('express')(), session = require('express-session'), http = require('http').Server(app), request = require('request'), exphbs = require('express-handlebars') app.engine('.hbs', exphbs({defaultLayout: 'single', extname: '.hbs'})) app.set('view engine', '.hbs') // function checkAuth (req, res, next) { // console.log(req.session); // console.log('checkAuth ' + req.url); // // don't serve /secure to those not logged in // // you should add to this list, for each and every secure url // // if (req.url === '/' && (!req.session || !req.session.authenticated)) { // // res.render('unauthorised', { status: 403 }); // // return; // // } // next() // } app.use(session({ secret: 'example' })) // app.use(checkAuth) var url = 'http://192.168.178.109:1024/' // Host the HTML File app.get('/', function(req, res){ if(!req.session.name){ res.render('login') return } request({ url: url, json: true, auth: { user: 'Simon', pass: 'password' } }, function(error, response, body){ var data = [] if (!error && response.statusCode === 200) { body.response.bot.accounts.forEach(el => { var tmp = el[Object.keys(el)] tmp.logs = "" tmp.settings = "" tmp.exp_percentage = tmp.experience/tmp.experienceForNextLevel data.push(tmp) }); res.render('index', { instances: data }) } else console.error('HTTP ERROR ' + response.statusCode + '') }); }) app.get('/assets/*', function(req, res){ res.sendFile(__dirname + req.originalUrl) }) app.post('/',function(req,res){ console.log(req); if(req.body.name === 'Admin' && req.body.pass === '1234'){ req.session.name = req.body.name res.end('success') } else { res.end('denied') } }); app.listen(8080)