Created
July 29, 2015 06:12
-
-
Save taesup/42ec0ff7b084a039983e to your computer and use it in GitHub Desktop.
answer to perfschool problem 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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