Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRhett Herring
Courses Plus Student 11,023 PointsThere was an error getting the profile for [profilename]. (Moved Permanently)
I'm running this on my local machine and getting the following error:
There was an error getting the profile for chalkers. (Moved Permanently)
I'm pretty sure its related to the profile JS which has the URL to the service as "http" not "https" when I change it so https and change the require to include var https = require("https"); I get an error https not supported.
Do I need to add a dev. cert on my machine to get the service via https?
2 Answers
Dennis O'Keeffe
32,820 PointsHey Rhett!
I'm just working back over the course now and saw your question. Same thing initially happened to me. What you need to have in your router.js is the var Profile = require('./profile.js') which I assume you currently have if you're having that issue.
Then, what I think is your current issue, is that you need to alter the profile.js file.
TreeHouse have moved to http, so you need to require the https module from Node.
Below is the code that should work. You basically just need to require that module and then change your var request to be https.get and the TreeHouse URL to https://tree...
Hope this helps to clarify the issue.
Happy coding!
var EventEmitter = require("events").EventEmitter;
var http = require("http");
var https = require("https"); //ADD THIS
var util = require("util");
/**
* An EventEmitter to get a Treehouse students profile.
* @param username
* @constructor
*/
function Profile(username) {
EventEmitter.call(this);
profileEmitter = this;
//Connect to the API URL (https://teamtreehouse.com/username.json)
var request = https.get("https://teamtreehouse.com/" + username + ".json", function(response) { //CHANGE THIS TO HTTPS
var body = "";
if (response.statusCode !== 200) {
request.abort();
//Status Code Error
profileEmitter.emit("error", new Error("There was an error getting the profile for " + username + ". (" + http.STATUS_CODES[response.statusCode] + ")"));
}
//Read the data
response.on('data', function (chunk) {
body += chunk;
profileEmitter.emit("data", chunk);
});
response.on('end', function () {
if(response.statusCode === 200) {
try {
//Parse the data
var profile = JSON.parse(body);
profileEmitter.emit("end", profile);
} catch (error) {
profileEmitter.emit("error", error);
}
}
}).on("error", function(error){
profileEmitter.emit("error", error);
});
});
}
util.inherits( Profile, EventEmitter );
module.exports = Profile;
J llama
12,631 Pointsdoesn't work
Rhett Herring
Courses Plus Student 11,023 PointsRhett Herring
Courses Plus Student 11,023 PointsArrgh!! I changed the URL in the sting to 'https" and added the require... I forgot to change the 'https.get' part.
Thanks!