diff --git a/README.md b/README.md index ad678975b..80a0929a7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ cnpmjs.org ======= -[![Build Status](https://secure.travis-ci.org/cnpm/cnpmjs.org.png)](http://travis-ci.org/cnpm/cnpmjs.org) [![Coverage Status](https://coveralls.io/repos/cnpm/cnpmjs.org/badge.png)](https://coveralls.io/r/cnpm/cnpmjs.org) [![Dependency Status](https://gemnasium.com/cnpm/cnpmjs.org.png)](https://gemnasium.com/cnpm/cnpmjs.org) +[![Build Status](https://secure.travis-ci.org/cnpm/cnpmjs.org.png)](http://travis-ci.org/cnpm/cnpmjs.org) [![Dependency Status](https://gemnasium.com/cnpm/cnpmjs.org.png)](https://gemnasium.com/cnpm/cnpmjs.org) [![NPM](https://nodei.co/npm/cnpmjs.org.png?downloads=true&stars=true)](https://nodei.co/npm/cnpmjs.org/) @@ -11,7 +11,8 @@ cnpmjs.org Private npm registry and web for Enterprise, base on [koa](http://koajs.com/), MySQL and [Simple Store Service](https://github.com/cnpm/cnpmjs.org/wiki/NFS-Guide). -@[JacksonTian](https://github.com/JacksonTian/) had a talk about [private npm](https://speakerdeck.com/jacksontian/qi-ye-ji-node-dot-jskai-fa). +* @[dead-horse](https://github.com/dead-horse): [What is cnpm?](http://deadhorse.me/slides/cnpmjs.html) +* @[JacksonTian](https://github.com/JacksonTian/) had a talk about [private npm](https://speakerdeck.com/jacksontian/qi-ye-ji-node-dot-jskai-fa). ![cnpm](https://docs.google.com/drawings/d/12QeQfGalqjsB77mRnf5Iq5oSXHCIUTvZTwECMonqCmw/pub?w=480&h=360) diff --git a/docs/web/readme.md b/docs/web/readme.md index ff89ed8cf..151339d66 100644 --- a/docs/web/readme.md +++ b/docs/web/readme.md @@ -1,6 +1,6 @@ # cnpmjs.org: Private npm registry and web for Enterprise -[![Build Status](https://secure.travis-ci.org/cnpm/cnpmjs.org.png)](http://travis-ci.org/cnpm/cnpmjs.org) [![Coverage Status](https://coveralls.io/repos/cnpm/cnpmjs.org/badge.png)](https://coveralls.io/r/cnpm/cnpmjs.org) [![Dependency Status](https://gemnasium.com/cnpm/cnpmjs.org.png)](https://gemnasium.com/cnpm/cnpmjs.org) +[![Build Status](https://secure.travis-ci.org/cnpm/cnpmjs.org.png)](http://travis-ci.org/cnpm/cnpmjs.org) [![Dependency Status](https://gemnasium.com/cnpm/cnpmjs.org.png)](https://gemnasium.com/cnpm/cnpmjs.org) [![NPM](https://nodei.co/npm/cnpmjs.org.png?downloads=true&stars=true)](https://nodei.co/npm/cnpmjs.org/) @@ -8,7 +8,8 @@ > Private npm registry and web for Enterprise, base on [koa](http://koajs.com/), MySQL and [Simple Store Service](https://github.com/cnpm/cnpmjs.org/wiki/NFS-Guide). -@[JacksonTian](https://github.com/JacksonTian/) had a talk about [private npm](https://speakerdeck.com/jacksontian/qi-ye-ji-node-dot-jskai-fa). +* @[dead-horse](https://github.com/dead-horse): [What is cnpm?](http://deadhorse.me/slides/cnpmjs.html) +* @[JacksonTian](https://github.com/JacksonTian/) had a talk about [private npm](https://speakerdeck.com/jacksontian/qi-ye-ji-node-dot-jskai-fa). ## Install your private npm registry diff --git a/middleware/web_not_found.js b/middleware/web_not_found.js index 80f77946e..153c20528 100644 --- a/middleware/web_not_found.js +++ b/middleware/web_not_found.js @@ -20,6 +20,12 @@ module.exports = function *notFound(next) { if (this.status) { return; } + + var m = /^\/([\w\-\_\.]+)\/?$/.exec(this.url); + if (m) { + return this.redirect('/package/' + m[1]); + } + this.status = 404; this.type = 'text/html'; this.charset = 'utf-8'; diff --git a/test/middleware/web_not_found.test.js b/test/middleware/web_not_found.test.js new file mode 100644 index 000000000..b65f8c71a --- /dev/null +++ b/test/middleware/web_not_found.test.js @@ -0,0 +1,63 @@ +/**! + * cnpmjs.org - test/middleware/web_not_found.test.js + * + * Copyright(c) cnpmjs.org and other contributors. + * MIT Licensed + * + * Authors: + * fengmk2 (http://fengmk2.github.com) + */ + +'use strict'; + +/** + * Module dependencies. + */ + +var should = require('should'); +var request = require('supertest'); +var app = require('../../servers/web'); + +describe('middleware/web_not_found.test.js', function () { + before(function (done) { + app.listen(0, done); + }); + + after(function (done) { + app.close(done); + }); + + describe('web_not_found()', function () { + it('should redirect /byte to /package/byte', function (done) { + request(app) + .get('/byte') + .expect('Location', '/package/byte') + .expect(302, done); + }); + + it('should redirect /byte/ to /package/byte', function (done) { + request(app) + .get('/byte/') + .expect('Location', '/package/byte') + .expect(302, done); + }); + + it('should 404 /~byte', function (done) { + request(app) + .get('/~byte') + .expect(404, done); + }); + + it('should 200 /package/byte', function (done) { + request(app) + .get('/package/byte') + .expect(200, done); + }); + + it('should 404 /package/byte404', function (done) { + request(app) + .get('/package/byte404') + .expect(404, done); + }); + }); +});