I am using Node.js.
I have a piece of code that works well in returning the expected response
and the response is received quickly:
if (req.accepts('json')) {
res.header('Content-Type', 'application/json');
res.send(res.locals.items, 200);
}
In addition to the Status 200, I want to add a message in the header.
Therefore, I modified the code above a little bit to be consistent with the
syntax, which is, *response.writeHead(statusCode, [reasonPhrase],
[headers])*, stated in the Node.js v0.10.26 Manual & Documentation
(http://nodejs.org/api/http.html):
if (req.accepts('json')) {
res.writeHead( 200, 'my_customizd_message', {'Content-Type' :
'application/json'} );
res.send(res.locals.items);
}
then, I got an error in the console saying "Error : can't set headers after
they are sent".
I tried something else:
if (req.accepts('json')) {
res.writeHead( 200, 'my_customizd_message', {'Content-Type' :
'application/json'} );
res.end();
}
There is no error message on the console. But, nothing is returned. The
code is running forever. I am hoping someone could help me out. Thank you
very much.
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.