var app = require('express')(), session = require('express-session'), http = require('http').Server(app), bodyParser = require('body-parser'), request = require('request'), exphbs = require('express-handlebars') app.engine('.hbs', exphbs({defaultLayout: 'single', extname: '.hbs'})) app.set('view engine', '.hbs') app.use(session({ resave: true, saveUninitialized: false, secret: '62gzrhufijw' })) app.use(bodyParser.json()) app.use(bodyParser.urlencoded({extended: true})) 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: req.session.name, pass: req.session.pass } }, 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){ if( req.body.name === 'Simon' && req.body.pass === 'password' || req.body.name === 'USER2' && req.body.pass === 'rfcgvhbßä06' ){ req.session.name = req.body.name req.session.pass = req.body.pass res.end('true') } else { res.end() } }) app.listen(8080)