Advertisement
dragonfree97

Untitled

Apr 18th, 2020
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const express = require('express');
  3. const fs = require('fs');
  4. const app = express();
  5. const cards = require('./public/achat/dat/cards.json');
  6.  
  7. var dir = path.join(__dirname, 'public');
  8.  
  9. app.use(express.static(dir));
  10.  
  11. app.set('views', path.join(__dirname, 'views'));
  12. app.set('view engine', 'jade');
  13.  
  14. var getInv = function(u) {
  15.     var inv = {};
  16.     var filelocation = './public/achat/inv/'+u+'.json';
  17.     if (fs.existsSync(filelocation)) {
  18.         delete require.cache[filelocation];
  19.         inv = require(filelocation);
  20.     } else {
  21.         return "error, file doesn't exist, looking in"+filelocation;
  22.     }
  23.     return inv;
  24. }
  25.  
  26. var getJadeableInv = function(inv) {
  27.     var myCards = {};
  28.     for (card in inv) {
  29.         if (inv[card].num > 0 && cards[card] != undefined) {
  30.             myCards[card] = cards[card];
  31.             console.log(cards[card]);
  32.             myCards[card].img = 'http://www.rtz.cool/achat/img/'+cards[card].img;
  33.             myCards[card].num = inv[card].num;
  34.         }
  35.     }
  36.     return myCards;
  37. }
  38.  
  39. app.get('/j/', function(req,res){
  40.     var inv = getInv(req.query.id);
  41.     var jaded = getJadeableInv(inv);
  42.     res.render('home', {
  43.         cards: jaded
  44.     });
  45. });
  46.  
  47. app.listen(80, function () {
  48.     console.log('Listening on http://localhost:80/');
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement