Skip to content

Instantly share code, notes, and snippets.

@TheOnlyArtz
Created August 28, 2017 09:11
Show Gist options
  • Save TheOnlyArtz/4088488fa5d6e73564bc2b22820feea8 to your computer and use it in GitHub Desktop.
Save TheOnlyArtz/4088488fa5d6e73564bc2b22820feea8 to your computer and use it in GitHub Desktop.
//This is the ROUTES.JS
const snekfetch = require('snekfetch');
const request = require('request');
const config = require('../config/config.json').token;
exports.home = function (req, res) {
res.render('home');
};
exports.notFound = function (req, res) {
res.render('notFound');
};
exports.getUserStatistics = async function (req, res) {
res.render('getUser', {
userGameTag: req.params.userGameTag,
stats: await getStats(config, req.params.user)
});
};
let getStats = async (token, user) => {
console.log(user)
// let stats = await snekfetch.get(`https://api.clashofclans.com/v1/players/${encodeURIComponent(user.replace(/[(#)]/g, ''))}`)
// .set({Authorization: token});
// let json = stats.body;
// return json;
};
//This is client.js
const app = require('express')(),
express = require('express'),
path = require('path'),
routes = require('./routes'),
snekfetch = require('snekfetch');
app.set('view engine', 'ejs');
// Serve static assets from the public folder
app.use(express.static(path.join(__dirname, 'public')));
// Routes
app.get('/', routes.home);
app.get('/user/:userGameTag?', routes.getUserStatistics);
app.get('/*', routes.notFound);
// Listen on port 3000
app.listen(process.env.PORT || 3000);
console.log('App is listening on port 3000');
const ejsLint = require('ejs-lint');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment