The final issue & PR

Decided to go for a bigger project this time. I found a website containing list of curated nodejs projects here: https://github.com/sqreen/awesome-nodejs-projects. After spending a couple days scrolling through these and picking out workable issues and repos, I’ve finally settled down on the following repo with a total of 400+ issues:

https://github.com/typicode/json-server

This repository lets front end developers spin up a fake back end REST API service real fast. Here’s a sample db.json file:

{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}

Put this configuration file in the server repo, spin up the server, then it will automatically generate these routes and hosts them for the front end developers to call. This is real convenient for someone who doesn’t have a lot of understanding in back end technology, and just want to make sure that their services properly sends out the desired requests and obtains the expected response from the backend service.

This is the particular issue I worked on: https://github.com/typicode/json-server/issues/1025

Through his screenshots, the guy who filed the issue argues that when a non-existing route is visited, the backend does not return an appropriate 404 response, indicating that the service does not exist.

However, in the code, we have the following:

router.use((req, res) => {
    if (!res.locals.data) {
      res.status(404)
      res.locals.data = {}
    }

    router.render(req, res)
...

The response is indeed returning a 404 status code, it’s just that the response’s data is empty. Therefore, it is causing confusion because visually there’s no difference in between returning a 200 status code with no data in the response message, or returning a 404 status code. I modified the response data object, giving it some information:

res.locals.data = {status_code: 404, error: 'Page not found'}

I updated the corresponding test cases inside the test suite and ran a local test. After everything has passed, I pushed my changes and created a pull request here: https://github.com/typicode/json-server/pull/1041. However, the ensuing TravisCI and AppVeyor builds failed. I went to check them out:

https://travis-ci.org/typicode/json-server/builds?utm_medium=notification&utm_source=github_status

After a brief analysis, it seems that the error is unrelated to my modifications, as the master branch’s CI builds have been failing since 2 months ago with the same error message. Perhaps I will work on the CI build errors in a separate issue/PR next time.

This probably concludes my hacktoberfest contributions; however, my contributions to the open-source community has just begun. It has been a lot of fun conversing with people openly on problems, and I’m definitely expecting to do more of these in the future. As of right now, I need to figure out how to get that T-shirt.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this: