Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
json body parse limit and bug fix.
Browse files Browse the repository at this point in the history
 * override json limit to default 10mb. fixed #209
 * fix #210 addPackageAndDist package version detect bug
  • Loading branch information
fengmk2 committed Feb 26, 2014
1 parent 291f551 commit 1f32ff3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var config = {
port: 19533,
pass: 'cnpmjs_dev'
},
jsonLimit: '10mb', // max request json body size
uploadDir: path.join(root, 'public', 'dist'),
// qiniu cdn: http://www.qiniu.com/, it free for dev.
qn: {
Expand Down
10 changes: 5 additions & 5 deletions controllers/registry/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,18 +477,18 @@ exports.addPackageAndDist = function *(next) {
var pkg = this.request.body;
var username = this.session.name;
var name = this.params.name;
var filename = Object.keys(pkg._attachments)[0];
var attachment = pkg._attachments[filename];
var version = filename.match(/\-([\.\d\w\_]+?)\.tgz$/);
var filename = Object.keys(pkg._attachments || {})[0];
var version = Object.keys(pkg.versions || {})[0];
if (!version) {
this.status = 403;
this.bdoy = {
error: 'version_error',
reason: filename + ' version not found',
reason: 'filename or version not found, filename: ' + filename + ', version: ' + version,
};
return;
}
version = version[1];

var attachment = pkg._attachments[filename];
var versionPackage = pkg.versions[version];
versionPackage._publish_on_cnpm = true;
var distTags = pkg['dist-tags'] || {};
Expand Down
2 changes: 1 addition & 1 deletion servers/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ app.use(rewrite('/favicon.ico', '/public/favicon.ico'));
app.keys = ['todokey', config.sessionSecret];
app.outputErrors = true;
app.use(session);
app.use(bodyParser());
app.use(bodyParser({limit: config.jsonLimit}));
app.use(auth());
app.use(notFound);

Expand Down

0 comments on commit 1f32ff3

Please sign in to comment.