const express = require('express');
const request = require('request-promise-native');
const logger = require('winston');

const router = new express.Router();


router.get('/', (req, res) => {
  request(`http://localhost:${req.app.locals.settings.port}/server/details`).then((serverJson) => {
    const serverDetails = JSON.parse(serverJson);

    request(`http://localhost:${req.app.locals.settings.port}/user/details`).then((userJson) => {
      const users = JSON.parse(userJson);
      const achievementsPromises = [];

      users.forEach((user) => {
        achievementsPromises.push(
          request(`http://localhost:${req.app.locals.settings.port}/user/${user.uuid}/achievements`)
        );
      });

      Promise.all(achievementsPromises).then((achievementsJson) => {
        const playerDataArray = [];

        users.forEach((user, index) => {
          const achievements = JSON.parse(achievementsJson[index]);

          const playerData =
            {
              name: user.name,
              achievements: achievements.achievements.map(x => ({ class: x })),
              score: achievements.score
            };

          playerDataArray.push(Object.assign(playerData));
        });

        const pageData = {
          serverDetails: `${serverDetails.connecturl}`,
          players: playerDataArray
        };

        res.render('index', pageData);
      }).catch(e => logger.log('error', e));
    }).catch(e => logger.log('error', e));
  }).catch(e => logger.log('error', e));
});

module.exports = router;

@@ -114,16 +114,71 @@
 nston');
+%0Aconst ServerHelper = require('../util/server-helper');
 %0A%0Aconst 
@@ -248,159 +248,128 @@
 %7B%0A  
-request(%60http://localhost:$%7Breq.app.locals.settings.port%7D/server/details%60).then((serverJson) =%3E %7B%0A    const serverDetails = JSON.parse(serverJson
+const serverHelper = new ServerHelper(req.app.locals.mcServerPath);%0A  const serverDetails = serverHelper.getDetails(
 );%0A%0A
-  
   re
@@ -460,26 +460,24 @@
 n) =%3E %7B%0A    
-  
 const users 
@@ -500,26 +500,24 @@
 rJson);%0A    
-  
 const achiev
@@ -534,26 +534,24 @@
 ises = %5B%5D;%0A%0A
-  
     users.fo
@@ -570,26 +570,24 @@
  =%3E %7B%0A      
-  
 achievements
@@ -601,18 +601,16 @@
 s.push(%0A
-  
         
@@ -710,15 +710,11 @@
     
-  
 );%0A
-  
     
@@ -722,18 +722,16 @@
 );%0A%0A    
-  
 Promise.
@@ -781,26 +781,24 @@
 sJson) =%3E %7B%0A
-  
       const 
@@ -826,18 +826,16 @@
 %0A%0A      
-  
 users.fo
@@ -863,26 +863,24 @@
 %3E %7B%0A        
- 
- 
 const achiev
@@ -930,26 +930,24 @@
 );%0A%0A        
-  
 const player
@@ -967,14 +967,10 @@
     
-  %7B%0A  
+%7B%0A
     
@@ -1002,26 +1002,24 @@
             
-  
 achievements
@@ -1084,18 +1084,16 @@
         
-  
 score: a
@@ -1116,26 +1116,24 @@
 e%0A          
-  
 %7D;%0A%0A        
@@ -1128,26 +1128,24 @@
 %7D;%0A%0A        
- 
- 
 playerDataAr
@@ -1187,18 +1187,16 @@
 ;%0A      
-  
 %7D);%0A%0A   
@@ -1194,26 +1194,24 @@
  %7D);%0A%0A      
- 
- 
 const pageDa
@@ -1217,18 +1217,16 @@
 ata = %7B%0A
-  
         
@@ -1275,26 +1275,24 @@
 %7D%60,%0A        
- 
- 
 players: pla
@@ -1306,26 +1306,24 @@
 Array%0A      
-  
 %7D;%0A%0A        
@@ -1320,18 +1320,16 @@
 %0A%0A      
- 
- 
 res.rend
@@ -1355,53 +1355,8 @@
 a);%0A
-      %7D).catch(e =%3E logger.log('error', e));%0A
     

Change index-controller to use ServerHelper