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

Commit

Permalink
feat: enable maxrequests middleware (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Jul 26, 2016
1 parent b0f0bc0 commit ea3bece
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 63 deletions.
20 changes: 6 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ TIMEOUT = 30000
MOCHA_OPTS =
DB = sqlite

install:
@npm install --build-from-source --registry=https://registry.npm.taobao.org \
--disturl=https://npm.taobao.org/mirrors/node

install-production production:
@NODE_ENV=production $(MAKE) install

jshint: install
jshint:
@node_modules/.bin/jshint .

init-database:
Expand All @@ -25,7 +18,7 @@ init-pg:
@psql -c 'DROP DATABASE IF EXISTS cnpmjs_test;'
@psql -c 'CREATE DATABASE cnpmjs_test;'

test: install init-database
test: init-database
@NODE_ENV=test DB=${DB} node_modules/.bin/mocha \
--reporter $(REPORTER) \
--timeout $(TIMEOUT) \
Expand All @@ -47,7 +40,7 @@ test-pg: init-pg

test-all: test-sqlite test-mysql

test-cov cov: install init-database
test-cov cov: init-database
@NODE_ENV=test DB=${DB} node \
node_modules/.bin/istanbul cover \
node_modules/.bin/_mocha \
Expand All @@ -67,7 +60,7 @@ test-cov-sqlite:
test-cov-mysql: init-mysql
@$(MAKE) test-cov DB=mysql

test-travis: install init-database
test-travis: init-database
@NODE_ENV=test DB=${DB} CNPM_SOURCE_NPM=https://registry.npmjs.com CNPM_SOURCE_NPM_ISCNPM=false \
node \
node_modules/.bin/istanbul cover \
Expand Down Expand Up @@ -98,15 +91,14 @@ test-travis-all: jshint test-travis-sqlite test-travis-mysql test-travis-pg
dev:
@NODE_ENV=development node node_modules/.bin/node-dev dispatch.js

contributors: install
contributors:
@node_modules/.bin/contributors -f plain -o AUTHORS

autod: install
autod:
@node_modules/.bin/autod -w \
--prefix "~" \
--exclude public,view,docs,backup,coverage \
--dep mysql \
--keep should,supertest,should-http,chunkstream,mm,pedding
@$(MAKE) install

.PHONY: test
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"koa": "^1.2.0",
"koa-limit": "^1.0.2",
"koa-markdown": "^2.0.1",
"koa-maxrequests": "^1.0.0",
"koa-middlewares": "^2.1.0",
"koa-mock": "^1.6.1",
"koa-safe-jsonp": "^0.3.1",
Expand Down
27 changes: 7 additions & 20 deletions servers/registry.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/**!
* cnpmjs.org - servers/registry.js
*
* Copyright(c) cnpmjs.org and other contributors.
* MIT Licensed
*
* Authors:
* dead_horse <dead_horse@qq.com>
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/

"use strict";

/**
* Module dependencies.
*/
'use strict';

var koa = require('koa');
var app = module.exports = koa();
Expand All @@ -28,25 +13,27 @@ var staticCache = require('../middleware/static');
var notFound = require('../middleware/registry_not_found');
var cors = require('kcors');
var proxyToNpm = require('../middleware/proxy_to_npm');
var maxrequests = require('koa-maxrequests');

app.use(maxrequests());
app.use(block());
middlewares.jsonp(app);
app.use(middlewares.rt({headerName: 'X-ReadTime'}));
app.use(middlewares.rt({ headerName: 'X-ReadTime' }));
app.use(middlewares.rewrite('/favicon.ico', '/favicon.png'));
app.use(staticCache);

app.keys = ['todokey', config.sessionSecret];
app.proxy = true;
app.use(middlewares.bodyParser({jsonLimit: config.jsonLimit}));
app.use(middlewares.bodyParser({ jsonLimit: config.jsonLimit }));
app.use(cors({
allowMethods: 'GET,HEAD'
allowMethods: 'GET,HEAD',
}));
app.use(auth());
app.use(proxyToNpm());
app.use(notFound);

if (config.enableCompress) {
app.use(middlewares.compress({threshold: 150}));
app.use(middlewares.compress({ threshold: 150 }));
}
app.use(middlewares.conditional());
app.use(middlewares.etag());
Expand Down
19 changes: 3 additions & 16 deletions servers/web.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/**!
* cnpmjs.org - servers/web.js
*
* Copyright(c) cnpmjs.org and other contributors.
* MIT Licensed
*
* Authors:
* dead_horse <dead_horse@qq.com>
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
*/

"use strict";

/**
* Module dependencies.
*/
'use strict';

var opensearch = require('../middleware/opensearch');
var notFound = require('../middleware/web_not_found');
Expand All @@ -32,13 +17,15 @@ var path = require('path');
var http = require('http');
var koa = require('koa');
var fs = require('fs');
var maxrequests = require('koa-maxrequests');

var app = koa();

jsonp(app);

var rootdir = path.dirname(__dirname);

app.use(maxrequests());
app.use(block());
app.use(middlewares.rt({headerName: 'X-ReadTime'}));
app.use(middlewares.rewrite('/favicon.ico', '/favicon.png'));
Expand Down
13 changes: 0 additions & 13 deletions worker.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/**!
* Copyright(c) cnpmjs.org and other contributors.
* MIT Licensed
*
* Authors:
* dead_horse <dead_horse@qq.com>
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
*/

'use strict';

/**
* Module dependencies.
*/

var graceful = require('graceful');
var registry = require('./servers/registry');
var web = require('./servers/web');
Expand Down

0 comments on commit ea3bece

Please sign in to comment.