This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7167989
commit c69d6a0
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/**! | ||
* cnpmjs.org - middleware/opensearch.js | ||
* | ||
* Copyright(c) cnpmjs.org and other contributors. | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me) | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var template = '<?xml version="1.0" encoding="UTF-8"?>\ | ||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">\ | ||
<ShortName>CNPM</ShortName>\ | ||
<Description>Search packages in CNPM.</Description>\ | ||
<Tags>CNPM</Tags>\ | ||
<Url method="get" type="text/html" template="http://${host}/browse/keyword/{searchTerms}"/>\ | ||
</OpenSearchDescription>'; | ||
|
||
var lastModifyDate = new Date(); | ||
|
||
module.exports = function publishable(req, res, next) { | ||
res.charset = res.charset || 'utf-8'; | ||
res.setHeader('Content-Type', 'text/xml'); | ||
res.send(template.replace('${host}', req.headers.host)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/**! | ||
* cnpmjs.org - test/middleware/opensearch.test.js | ||
* | ||
* Copyright(c) cnpmjs.org and other contributors. | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me) | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var should = require('should'); | ||
var request = require('supertest'); | ||
var app = require('../../servers/web'); | ||
|
||
describe('middleware/opensearch.test.js', function () { | ||
before(function (done) { | ||
app.listen(0, done); | ||
}); | ||
after(function (done) { | ||
app.close(done); | ||
}); | ||
|
||
describe('GET /opensearch.xml', function () { | ||
it('should get 200', function (done) { | ||
request(app) | ||
.get('/opensearch.xml') | ||
.set('host', 'localhost:7002') | ||
.expect(/http:\/\/localhost:7002/, done); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters