Skip to content

Commit

Permalink
Fix ?meta listings
Browse files Browse the repository at this point in the history
Fixes ?meta listings (and other requests) for packages with a root
"directory" entry.

Fixes unpkg#210
  • Loading branch information
mjackson committed Aug 1, 2019
1 parent e757feb commit 88a4213
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
32 changes: 32 additions & 0 deletions modules/__tests__/serveMetadata-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import request from 'supertest';

import createServer from '../createServer.js';

describe('A request for metadata', () => {
let server;
beforeEach(() => {
server = createServer();
});

it('returns 200', done => {
request(server)
.get('/[email protected]/?meta')
.end((err, res) => {
expect(res.statusCode).toBe(200);
expect(res.headers['content-type']).toMatch(/\bapplication\/json\b/);
done();
});
});

describe('with a package that includes a root "directory" entry', () => {
it('returns 200', done => {
request(server)
.get('/[email protected]/?meta')
.end((err, res) => {
expect(res.statusCode).toBe(200);
expect(res.headers['content-type']).toMatch(/\bapplication\/json\b/);
done();
});
});
});
});
2 changes: 1 addition & 1 deletion modules/actions/serveDirectoryBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function findMatchingEntries(stream, filename) {
// so we shorten that to just `/index.js` here. A few packages use a
// prefix other than `package/`. e.g. the firebase package uses the
// `firebase_npm/` prefix. So we just strip the first dir name.
path: header.name.replace(/^[^/]+/, ''),
path: header.name.replace(/^[^/]+\/?/, '/'),
type: header.type
};

Expand Down
2 changes: 1 addition & 1 deletion modules/actions/serveDirectoryMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function findMatchingEntries(stream, filename) {
// so we shorten that to just `/index.js` here. A few packages use a
// prefix other than `package/`. e.g. the firebase package uses the
// `firebase_npm/` prefix. So we just strip the first dir name.
path: header.name.replace(/^[^/]+/, ''),
path: header.name.replace(/^[^/]+\/?/, '/'),
type: header.type
};

Expand Down
2 changes: 1 addition & 1 deletion modules/actions/serveFileBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function findEntry(stream, filename) {
// so we shorten that to just `/index.js` here. A few packages use a
// prefix other than `package/`. e.g. the firebase package uses the
// `firebase_npm/` prefix. So we just strip the first dir name.
path: header.name.replace(/^[^/]+/, ''),
path: header.name.replace(/^[^/]+\/?/, '/'),
type: header.type
};

Expand Down
2 changes: 1 addition & 1 deletion modules/actions/serveFileMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function findEntry(stream, filename) {
// so we shorten that to just `/index.js` here. A few packages use a
// prefix other than `package/`. e.g. the firebase package uses the
// `firebase_npm/` prefix. So we just strip the first dir name.
path: header.name.replace(/^[^/]+/, ''),
path: header.name.replace(/^[^/]+\/?/, '/'),
type: header.type
};

Expand Down

0 comments on commit 88a4213

Please sign in to comment.