We then modify the server so that the request handler can return some meaningful information.
Let’s see how to implement it:
1. Let the request handler directly return (return()) the information they want to display to the user through the onRequest function.
2. Let’s start by having the request handler return the information that needs to be displayed in the browser.
We need to modify requestHandler.js to the following form:
Similarly, request routing needs to return to the server the information returned to it by the request handler.
Therefore, we need to modify router.js to the following form:
As shown in the above code, when the request cannot be routed, we also return some related error information.
Finally, we need to refactor our server.js so that it responds to the browser with the content returned by the request handler via the request route, like this:
If we run the refactored application:
Request http://localhost:8888/start, the browser will output "Hello Start",
Requesting http://localhost:8888/upload will output "Hello Upload",
And requesting http://localhost:8888/foo will output "404 Not found".
This feels good. In the next section we will learn about a concept: blocking operations.