const express = require('express'); const morgan = require('morgan' ); const fs = require('fs' ); const http = require('http' ); const config = require('./config.js').load(process.argv[2]); const app = express(); app.use("/", morgan("dev")); app.use("/", (request, response, next) => { /*if (request.headers['accept'].split(',')[0] === 'text/html') { let path = request.url; if (path === '/') { path = "/index.html"; } path = 'webpage' + path; fs.readFile(path, 'utf8', (err, fileData) => { if (err) { response.statusCode = 500; response.statusMessage = 'Unkown file read error'; console.log(err); } if (path === 'webpage/index.html') { console.log("ummmm"); dbRequest = http.get("http://localhost:4730/achievements", dbResponse => { console.log("Yesting?"); dbResponse.on('data', achievementData => { console.log("Hello?"); achievementData = JSON.parse(achievementData); let list = ""; for (const achievement of achievementData.achievements) { list = list + `
Achievement Icon.png

${achievement.name}

${achievement.description}

${achievement.gameID}

`; } response.statusCode = 200; response.statusMessage = 'OK'; response.write(Buffer.from(fileDate.replace("\${list}", list), 'utf8')); response.end(); }); }); } }); } else { next(); }*/ next(); }); app.use("/", express.static("webpage")); app.listen(config.port);