-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
53 lines (38 loc) · 1.12 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var Profile = require("./profile.js");
// Handle HTTP GET/ and POST/ i.e Home
function home(request,response){
//if url == "/" && GET
if(request.url === "/"){
//show search
response.statusCode = 200;
response.setHeader('Content-Type', 'text/plain');
response.write("Header\n");
response.write("Search\n");
response.end("Footer\n");
}
//if url == "/" && POST
//redirect to /:username
}
// Handle HTTP route GET /:username i.e /chalkers
function user(request,response){
//if url == "/..."
var username = request.url.replace("/","")
if(username.length > 0){
response.statusCode = 200;
response.setHeader('Content-Type', 'text/plain');
response.write("Header\n");
//get json from treehouse
var studentProfile = new Profile("chalkers");
response.write(username +"\n");
response.end("Footer\n");
// on "end"
studentProfile.on("end", function(profileJSON){
//show profile
});
//show profile
// on "error"
//show error
}
}
module.exports.home = home;
module.exports.user = user;