Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Build a Simple Dynamic Site with Node.js Handling Routes in Node.js Home Route

Michael Randall
PLUS
Michael Randall
Courses Plus Student 10,643 Points

Workspace Unavailable on Create Web Server Node.js

I keep getting the message: "Workspace Unavailable - This is a preview link for a Treehouse Workspace that is not currently active. If you are the workspace owner, you can launch it again via the Treehouse site."

I've followed the instructions on the page and started the server in the console, then when I select view port 8080, it get the message from above. Here is my current code:

var https = require('https');
https.createServer(function (request, response){
  homeRoute(request, response);
}).listen(8080);
console.log('Server running at http://<workspace-url>/');

//2. Handle HTTP route GET / and POST / i.e. Home
function homeRoute(request, response){
  //if url == "/" && GET
  if(request.url === "/"){
    //show search
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.write("Header\n");
    response.write("Search\n");
    response.write('Footer\n');
  }
  //if url == "/" && POST
    //redirect to /:username
}

All of the other files are the same from the exercise. Are there any recommendations to get this working in the browser?

4 Answers

Try changing your code to use http instead of https:

var http = require('http');
http.createServer(function (request, response){
  homeRoute(request, response);
}).listen(8080);
console.log('Server running at http://<workspace-url>/');

//2. Handle HTTP route GET / and POST / i.e. Home
function homeRoute(request, response){
  //if url == "/" && GET
  if(request.url === "/"){
    //show search
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.write("Header\n");
    response.write("Search\n");
    response.write('Footer\n');
  }
  //if url == "/" && POST
    //redirect to /:username
}

They are in fact completely different modules...

I copied and pasted this code into my workspaces and it still doesn't work. I get the same "Workspace Unavailable" screen error.

i am having same issue says the server is not found . can any one help me

Hi, i had the same issue but figured it out, but I still have a question regarding this.when creating the server what stops the https module from working and not the htttp module. Is it the additional server protocols that are associated with https? What additional steps would you need to make the https module work on the workspace listening ports.

How did you figure it out?

I am still having issues with it not loading in the browser. Do I need to do something with the html file?