braveheart1989

Untitled

May 24th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let fs = require('fs');
  2. let path = require('path');
  3. let database = require('../config/database')
  4.  
  5. module.exports = (req, res) => {
  6.     if(req.headers.statusheader === "Full") {
  7.         let filePath = path.normalize(path.join(__dirname, '../content/status.html'));
  8.         fs.readFile(filePath, (err, data) => {
  9.             if(err) {
  10.                 console.log(err);
  11.                 res.writeHead(404);
  12.                 res.write('404 Not Found');
  13.                 res.end();
  14.             }
  15.  
  16.             res.writeHead(200, {
  17.                 'Content-Type': 'text/html'
  18.             });
  19.  
  20.             let imagesCount = database.images.getAll().length;
  21.             data = data.toString().replace('{content}', `There are currently ${imagesCount} images.`)
  22.             res.write(data);
  23.             res.end();
  24.         })
  25.     } else {
  26.         return true;
  27.     }
  28. }
Add Comment
Please, Sign In to add comment