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

Commit

Permalink
redirect /dist/xxx.tgz => http://dist.u.qiniudn.com/xxx.tgz fixed #249
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Mar 5, 2014
1 parent bd8686c commit 7794d10
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var config = {
debug: false
},

disturl: 'http://dist.u.qiniudn.com',
logoURL: 'http://ww4.sinaimg.cn/large/69c1d4acgw1ebfly5kjlij208202oglr.jpg',
registryHost: 'r.cnpmjs.org',
customFooter: '', // you can add copyright and site total script html here
Expand Down
23 changes: 23 additions & 0 deletions controllers/web/dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**!
* cnpmjs.org - controllers/web/dist.js
*
* Copyright(c) cnpmjs.org and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/

"use strict";

/**
* Module dependencies.
*/

var config = require('../../config');

exports.redirect = function *(next) {
var params = this.params;
var url = config.disturl + (params[0] || '/');
this.redirect(url);
};
5 changes: 4 additions & 1 deletion routes/web.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/**!
* cnpmjs.org - routes/web.js
*
* Copyright(c) cnpmjs.org and other contributors.
Expand All @@ -19,6 +19,7 @@ var pkg = require('../controllers/web/package');
var user = require('../controllers/web/user');
var sync = require('../controllers/sync');
var total = require('../controllers/total');
var dist = require('../controllers/web/dist');

function routes(app) {
app.get('/total', total.show);
Expand All @@ -34,6 +35,8 @@ function routes(app) {
app.get('/sync', pkg.displaySync);

app.get('/_list/search/search', pkg.rangeSearch);

app.get(/^\/dist(\/.+)?/, dist.redirect);
}

module.exports = routes;
37 changes: 37 additions & 0 deletions test/controllers/web/dist.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**!
* cnpmjs.org - test/controllers/web/dist.test.js
*
* Copyright(c) cnpmjs.org and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.cnpmjs.org)
*/

'use strict';

/**
* Module dependencies.
*/

var should = require('should');
var request = require('supertest');
var app = require('../../../servers/web');

describe('controllers/web/dist.test.js', function () {
before(function (done) {
app.listen(0, done);
});
after(function (done) {
app.close(done);
});

describe('GET /dist', function (done) {
it('should 302 to config.disturl', function (done) {
request(app)
.get('/dist')
.expect('Location', 'http://dist.u.qiniudn.com/')
.expect(302, done);
});
});
});

0 comments on commit 7794d10

Please sign in to comment.