<commit_before>var express = require('express'),
    mainRouter = express.Router(),
    path = require('path'),
    fs = require('fs');

// home page
mainRouter.get('/', function(req, res, next) {
  res.render('index', { title: 'Lora' });
});

// Retrieve data from config file in config/device.json
// TODO put into external module
mainRouter.get('/:dev_eui', function (req, res, next) {
  
  var currentdevice = JSON.parse(fs.readFileSync(path.join(__dirname, './../config/device.json'), 'utf8'));
  
  console.log('req.params: ', req.params);
  
  var id = req.params.dev_eui;
  
  res.locals.dev_eui = currentdevice['dev_eui'];
  res.locals.payload = currentdevice['payload'];
  res.locals.encrypted_payload = currentdevice['encrypted_payload'];
  
  console.log('id: ', id);
  console.log('res.locals.dev_eui',res.locals.dev_eui);
  
  if ( id === res.locals.dev_eui) {
    
    res.render('checkpayload', { title: 'Current configuration data',
                                 id: 'deveui',
                                 data: res.locals });
  } else {
    
      var err = new Error('Device not found.');
      err.status = 404;
      next(err);
  }
});

module.exports = mainRouter;<commit_msg>fixed error when looking up device data<commit_after>var express = require('express'),
    mainRouter = express.Router(),
    path = require('path'),
    fs = require('fs');

// home page
mainRouter.get('/', function(req, res, next) {
  res.render('index', { title: 'Lora' });
});

// Retrieve data from config file in config/device.json
// TODO put into external module
mainRouter.get('/:dev_eui', function (req, res, next) {

  var currentdevice = JSON.parse(fs.readFileSync(path.join(__dirname, './../config/device.json'), 'utf8'));

  console.log('req.params: ', req.params);

  var id = req.params.dev_eui;

  res.locals.dev_eui = currentdevice['dev_eui'];
  res.locals.payload = currentdevice['payload'];
  res.locals.encrypted_payload = currentdevice['encrypted_payload'];

  console.log('id: ', id);
  console.log('res.locals.dev_eui',res.locals.dev_eui);

  if ( id === res.locals.dev_eui) {

    res.render('checkpayload', { title: 'Current configuration data',
                                 id: 'deveui',
                                 data: res.locals });
  } else {

      var err = new Error('Device not found.');
      err.status = 404;
      res.render(err);
  }
});

module.exports = mainRouter;
{'fraction_non_alphanumeric': 0.1672171758876961, 'fraction_numerical': 0.0033030553261767133, 'mean_word_length': 2.9721311475409835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5167806', 'n_tokens_mistral': 789, 'n_tokens_neox': 775, 'n_words': 161}