require('dotenv').load()

var fs = require('fs')
var path = require('path')

var PREFIX = process.env.data_directory
var ROOT_PATH = path.join(PREFIX, 'Monitoring')
var TILES_FOLDER = path.join(path.join(ROOT_PATH, 'Maps'), 'Tiles')

function listTileLayers (req, res, next) {
  fs.readdir(TILES_FOLDER, function (err, files) {
    if (err) {
      res.status(500)
      res.render('error', {
        message: err.message,
        error: err
      })
    } else {
      var names = []
      for (var index in files) {
        names.push({name: files[index]})
      }
      res.json(names)
    }
  })
}

module.exports = {
  listTileLayers: listTileLayers
}

@@ -350,44 +350,16 @@
 res.
-status(500)%0A      res.render('error'
+json(500
 , %7B%0A

Set status with json response for tile-layers.