Skip to content

Instantly share code, notes, and snippets.

@taesup
Created July 29, 2015 06:12
Show Gist options
  • Save taesup/42ec0ff7b084a039983e to your computer and use it in GitHub Desktop.
Save taesup/42ec0ff7b084a039983e to your computer and use it in GitHub Desktop.
answer to perfschool problem 1
'use strict';
var fs = require('fs');
var path = require('path');
var express = require('express');
var psi = require('psi');
var app = express();
var port = process.env.PORT || 7777;
app.get('/', home);
app.get('/insights', insights);
app.listen(port, listening);
function listening () {
console.log('Listening on port', port);
}
function home (req, res) {
var file = path.join(__dirname, 'index.html');
var index = fs.readFileSync(file, 'utf8');
res.send(index);
}
function insights (req, res) {
psi('https://cpwxfypefz.localtunnel.me', function(err, data) {
var resources = {
css: data.pageStats.numberCssResources,
js: data.pageStats.numberJsResources,
hosts: data.pageStats.numberHosts,
total: data.pageStats.numberResources
};
res.send({ resources: resources });
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment