Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change name of the handler function to router #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions step04.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ An endpoint is the part of the url which comes after `/`, in above case it's `/

There is a particular method on the request object that allows you to see the endpoint, which was put in the url.

**Inside your handler function, at the top, add the following:**
**Inside your router function, at the top, add the following:**

```js
var endpoint = request.url;
Expand All @@ -25,7 +25,7 @@ All requests use one of the HTTP methods. The main ones are: `GET, POST, PUT, DE

### Check which method was used for your request.

**Type inside your handler function at the top :**
**Type inside your router function at the top :**

```js
var method = request.method;
Expand All @@ -35,7 +35,7 @@ console.log(method);

## 1. Create your own endpoints and send different responses.

Now, you know how to get the endpoint using `request.url`. Change your handler function so that it sends one message when requested url is `/node` and another one when requested url is `/girls`.
Now, you know how to get the endpoint using `request.url`. Change your router function so that it sends one message when requested url is `/node` and another one when requested url is `/girls`.

Good luck :) Feel free to discuss it with your team or mentor.

Expand All @@ -61,7 +61,7 @@ Let's try it.
var http = require('http');
var fs = require('fs');

function handler (request, response) {
function router (request, response) {

if (endpoint === "/") {
response.writeHead(200, {"Content-Type": "text/html"});
Expand Down