收集一些坑
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
var http = require('http');
var url = require('url');
http.createServer(function (req, res) {
var query = url.parse(req.url, true).query;
var name = query.name || '';
res.send(name.trim());
}).listen(3000);
GET http://localhost:3000?name=foo&name=bar
throw error;
query.name = [foo, bar]; [].trim()
http.createServer(function (req, res) {
parseBody(req, function onBody(err, body) {
if (err) {
res.statusCode = 500;
return res.end(err.message);
}
var keys = Object.keys(body);
res.end(keys.join(','));
}
}).listen(3000);
function parseBody(req, callback) {
// 获取原始的请求 body
rawBody(req, function (err, content) {
if (err) return callback(err);
var body = {};
try {
body = JSON.parse(content);
} catch (err) {
return callback(err);
}
return callback(null, body);
});
}
POST 'null' Boom! (JSON.parse('null') => null)
POST '"hello"' Boom! (JSON.parse('"hello"') => 'hello')
co-body
function parseBody(req, callback) {
rawBody(req, function (err, content) {
if (err) return callback(err);
var body = {};
try {
body = JSON.parse(content);
// 严格的只接受 object 作为 body
if (!body || typeof body !== 'object') {
throw new Error('request body must be object');
}
} catch (err) {
return callback(err);
}
return callback(null, body);
});
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the two linked maintainable-nodejs sections and the inline JavaScript examples first. Define the intended scope and location of the collected notes; done requires an agreed scope and documented guidance for the shown query and JSON-body cases, since no repository file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100