franciscop / server

:desktop_computer: Simple and powerful server for Node.js
https://serverjs.io/
MIT License
3.56k stars 173 forks source link

Basic usage example in docs is incorrect #132

Closed Darkle closed 3 years ago

Darkle commented 3 years ago

Describe the bug The example shown in https://serverjs.io/documentation/#basic-usage is incorrect. The status() call needs a .end() on it, otherwise it times out.

To Reproduce Running the following code:

const server = require('server');
const { get } = server.router;

server([
  get(ctx => status(404))
])

And then going to http://localhost:3000 the web page times out.

Expected behavior The web page should not time out.

I believe the status() call needs a .end on it:

server([
  get(ctx => status(404).end())
])
franciscop commented 3 years ago

Thank you for the bug report! This is indeed a code bug, not a documentation bug. When doing get(() => status(404)) the internal variable ctx.req.solved is set to true even if it hasn't been truly resolved. This is done on purpose to avoid unintended cascading effects (e.g. get('/about') and then get('/:userId') both being called on /about).

The fix is here, would love a PR review if you have 5 mins:

https://github.com/franciscop/server/pull/133

franciscop commented 3 years ago

Fixed on v1.0.33 🎉