Using only the net
module create an HTTP server that responds with
different messages based on path.
Refer to Getting Started in the lab submission instructions for complete setup, configuration, deployment, and submission instructions.
The starter-code
includes basic scaffolding and tests for parseRequest
and createResponse
.
parseRequest
takes a rawRequest
(an HTTP request message). It should take that rawRequest
and return an object with body
, method
, and path
from the rawRequest
.
module.exports = ({ body = '', contentType = 'text/html', status = '200 OK' }) => {
return `
HTTP/1.1
${body} `.trim(); };
createResponse
takes an object with body
, contentText
, and status
. It should use
that information to construct an HTTP response message. Make sure to set the:
- status
- Content-Length header
- Content-Type header
- HTTP body
path | method | body |
---|---|---|
/ |
GET |
plain text "hi" |
/echo |
POST |
status code 200 and plain text with the request body |
/red |
GET |
html with an h1 and the word red |
/green |
GET |
html with an h1 and the word green |
/blue |
GET |
html with an h1 and the word blue |
Everything else respond with 404 and a not found HTML page.
Use supertest
to test your routes.
parseRequest
- 4 pointscreateResponse
- 4 points- handle routes - 2 points
Refer to the the lab submission instructions for the complete lab submission process and expectations