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 trial

JavaScript

JP Chaufan Field
JP Chaufan Field
1,655 Points

Cant access teamtreehouse API

Im on the course to learn node.js by using it from the console. im working out of the workspace and, in the video, the guy is accessing http://teamtreehouse.com/chalkers.json (or other_usernames.json)

his request was 200 ok, but i kept on getting 301 moved permanently. i noticed that, in my browser's url bar, it always redirects me to https rather than http, which explains the 301 status response instead of 200.

but now I cant really follow along in the video because i cant connect to the api... Is this a mistake on team treehouse for making the api secure? or some mistake on my part?

1 Answer

andren
andren
28,558 Points

I'm assuming you are going though the Node.js course, if so then this issue is addressed in the teacher's note of this video.

I'll quote the relevant part:

Getting Error 301?

On October 20th 2015, we upgraded our website to only use HTTPS rather than just HTTP. This means more security for anyone using our site.

This update does include some breaking changes to our code. But it's simple to fix.

Replace any references to http to https. For example:

var https = require("https"); Modify any links from "http://teamtreehouse.com/" to "https://teamtreehouse.com/".

The only exception to this is using http.STATUS_CODES. While the APIs for http and https are closely mirrored https don't have the STATUS_CODES object. You still need to use https for all the API calls but you'll also need http for access to STATUS_CODES.

var http = require("http");

http.STATUS_CODES;

So basically just add a require statement for https like you did with http (but keep the http import around) and then replace all references to http with https, except for when you are using the STATUS_CODES since that is only found in the http module.