Skip to content

Commit 9011ff5

Browse files
committedMay 6, 2017
prettify code and clean up
1 parent 003e99c commit 9011ff5

File tree

11 files changed

+17
-24
lines changed

11 files changed

+17
-24
lines changed
 

‎app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const router = require('./router.js');
44
const port = 3000;
55

66
const server = http.createServer((req, res) => {
7-
router.home(req,res);
7+
router.home(req, res);
88
router.user(req, res);
99
}).listen(port, () => {
1010
console.log(`Server running at http://:${port}/`);
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎profile.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Profile(username) {
1515
profileEmitter = this;
1616

1717
//Connect to the API URL (https://teamtreehouse.com/username.json)
18-
var request = https.get("https://teamtreehouse.com/" + username + ".json", function(response) {
18+
var request = https.get("https://teamtreehouse.com/" + username + ".json", function (response) {
1919
var body = "";
2020

2121
if (response.statusCode !== 200) {
@@ -31,7 +31,7 @@ function Profile(username) {
3131
});
3232

3333
response.on('end', function () {
34-
if(response.statusCode === 200) {
34+
if (response.statusCode === 200) {
3535
try {
3636
//Parse the data
3737
var profile = JSON.parse(body);
@@ -40,12 +40,12 @@ function Profile(username) {
4040
profileEmitter.emit("error", error);
4141
}
4242
}
43-
}).on("error", function(error){
43+
}).on("error", function (error) {
4444
profileEmitter.emit("error", error);
4545
});
4646
});
4747
}
4848

49-
util.inherits( Profile, EventEmitter );
49+
util.inherits(Profile, EventEmitter);
5050

5151
module.exports = Profile;

‎render.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ var fs = require("fs");
22

33
function mergeValues(values, content) {
44
for (var key in values) {
5-
content = content.replace("{{"+key+"}}", values[key])
5+
content = content.replace("{{" + key + "}}", values[key])
66
}
77
return content;
88
}
99

10-
11-
function view (templateName, values, res) {
12-
var fileContent = fs.readFileSync('./views/'+templateName+'.html', 'utf8');
10+
function view(templateName, values, res) {
11+
var fileContent = fs.readFileSync('./views/' + templateName + '.html', 'utf8');
1312
fileContent = mergeValues(values, fileContent);
1413
res.write(fileContent);
1514
}

‎router.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function home(req, res) {
1010
render.view("header", {}, res);
1111
render.view("search", {}, res);
1212
render.view("footer", {}, res);
13-
res.end('End of the response\n');
13+
res.end();
1414
} else {
1515
req.on("data", function (postBody) {
1616
var query = querystring.parse(postBody.toString());
@@ -36,15 +36,15 @@ function user(req, res) {
3636
render.view("header", {}, res);
3737
render.view("profile", values, res);
3838
render.view("footer", {}, res);
39-
res.end('End of the response\n');
39+
res.end();
4040
});
4141

4242
studentProfile.on('error', function (err) {
4343
render.view("header", {}, res);
4444
render.view("error", { errorMessage: err.message }, res)
4545
render.view("search", {}, res);
4646
render.view("footer", {}, res);
47-
res.end('End of the response\n');
47+
res.end();
4848
});
4949
}
5050
}

‎views/error.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
<div id="error">{{errorMessage}}</div>
2-
<img src="https://upload.wikimedia.org/wikipedia/commons/0/0c/Cz-Error.png" alt="Error" id="searchIcon">
1+
<div id="error">{{errorMessage}}</div>

‎views/header.html

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<!DOCTYPE html>
22
<html>
3-
43
<head>
54
<meta charset="utf-8">
65
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
@@ -47,16 +46,16 @@
4746
}
4847

4948
.button {
50-
border-color: #5FB6E1;
51-
background: #5FB6E1;
49+
border-color: blue;
50+
background: blue;
5251
color: #fff;
5352
}
5453

5554
#error {
5655
width: 100%;
5756
padding: 22px 0;
58-
background: #FFE6B2;
59-
color: #C5A14E;
57+
background: #ff0000;
58+
color: lightyellow ;
6059
position: absolute;
6160
left: 0;
6261
top: 0;
@@ -65,7 +64,7 @@
6564
#profile {
6665
background: #fff;
6766
border-radius: 4px;
68-
border: 1px solid #D5DDE4;
67+
border: 1px solid blue;
6968
padding: 40px 0 0;
7069
margin: -40px 0 0;
7170
}

‎views/profile.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<div id="profile">
2-
32
<img src="{{avatarUrl}}" alt="Avatar" id="avatar">
4-
53
<p><span>{{username}}</span></p>
6-
74
<ul>
85
<li><span>{{badges}}</span> Badges earned</li>
96
<li><span>{{javascript}}</span> JavaScript points</li>

‎views/search.html

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<img src="http://simpleicon.com/wp-content/uploads/magnifier-7-256x256.png" alt="Magnifying Glass" id="searchIcon">
2-
32
<form action="/" method="POST">
43
<input type="text" placeholder="Enter a Treehouse username" id="username" name="username">
54
<input type="submit" value="search" class="button">

0 commit comments

Comments
 (0)
Please sign in to comment.