Add /_metadata and /_module functions
Also deprecate ?meta and ?module query params.
This commit is contained in:
parent
90fecd39c2
commit
5df576c6be
|
@ -1,13 +1,13 @@
|
|||
import serveAutoIndexPage from './serveAutoIndexPage';
|
||||
import serveHTMLModule from './serveHTMLModule';
|
||||
import serveJavaScriptModule from './serveJavaScriptModule';
|
||||
import serveMetadata from './serveMetadata';
|
||||
import serveModule from './serveModule';
|
||||
import serveStaticFile from './serveStaticFile';
|
||||
|
||||
/**
|
||||
* Send the file, JSON metadata, or HTML directory listing.
|
||||
*/
|
||||
export default function serveFile(req, res) {
|
||||
// Deprecated.
|
||||
if (req.query.meta != null) {
|
||||
return serveMetadata(req, res);
|
||||
}
|
||||
|
@ -16,19 +16,9 @@ export default function serveFile(req, res) {
|
|||
return serveAutoIndexPage(req, res);
|
||||
}
|
||||
|
||||
// Deprecated.
|
||||
if (req.query.module != null) {
|
||||
if (req.entry.contentType === 'application/javascript') {
|
||||
return serveJavaScriptModule(req, res);
|
||||
}
|
||||
|
||||
if (req.entry.contentType === 'text/html') {
|
||||
return serveHTMLModule(req, res);
|
||||
}
|
||||
|
||||
return res
|
||||
.status(403)
|
||||
.type('text')
|
||||
.send('?module mode is available only for JavaScript and HTML files');
|
||||
return serveModule(req, res);
|
||||
}
|
||||
|
||||
serveStaticFile(req, res);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import serveHTMLModule from './serveHTMLModule';
|
||||
import serveJavaScriptModule from './serveJavaScriptModule';
|
||||
|
||||
export default function serveModule(req, res) {
|
||||
if (req.entry.contentType === 'application/javascript') {
|
||||
return serveJavaScriptModule(req, res);
|
||||
}
|
||||
|
||||
if (req.entry.contentType === 'text/html') {
|
||||
return serveHTMLModule(req, res);
|
||||
}
|
||||
|
||||
res
|
||||
.status(403)
|
||||
.type('text')
|
||||
.send('module mode is available only for JavaScript and HTML files');
|
||||
}
|
|
@ -1,20 +1,15 @@
|
|||
import createSearch from '../utils/createSearch';
|
||||
|
||||
/**
|
||||
* Redirect old URLs that we no longer support.
|
||||
*/
|
||||
export default function redirectLegacyURLs(req, res, next) {
|
||||
// Permanently redirect /_meta/path to /path?meta.
|
||||
// Permanently redirect /_meta/path to /_metadata/path
|
||||
if (req.path.match(/^\/_meta\//)) {
|
||||
req.query.meta = '';
|
||||
return res.redirect(301, req.path.substr(6) + createSearch(req.query));
|
||||
return res.redirect(301, '/_metadata' + req.path.substr(6));
|
||||
}
|
||||
|
||||
// Permanently redirect /path?json => /path?meta
|
||||
if (req.query.json != null) {
|
||||
delete req.query.json;
|
||||
req.query.meta = '';
|
||||
return res.redirect(301, req.path + createSearch(req.query));
|
||||
return res.redirect(301, '/_metadata' + req.path);
|
||||
}
|
||||
|
||||
next();
|
||||
|
|
|
@ -2,8 +2,8 @@ import createSearch from '../utils/createSearch';
|
|||
|
||||
const knownQueryParams = {
|
||||
main: true, // Deprecated, see #63
|
||||
meta: true,
|
||||
module: true
|
||||
meta: true, // Deprecated
|
||||
module: true // Deprecated
|
||||
};
|
||||
|
||||
function isKnownQueryParam(param) {
|
||||
|
|
|
@ -3,6 +3,8 @@ import express from 'express';
|
|||
// import serveAuth from './actions/serveAuth';
|
||||
import serveFile from './actions/serveFile';
|
||||
import serveMainPage from './actions/serveMainPage';
|
||||
import serveMetadata from './actions/serveMetadata';
|
||||
import serveModule from './actions/serveModule';
|
||||
import servePublicKey from './actions/servePublicKey';
|
||||
import serveStats from './actions/serveStats';
|
||||
|
||||
|
@ -49,6 +51,36 @@ app.use(
|
|||
})
|
||||
);
|
||||
|
||||
app.use(
|
||||
'/_metadata',
|
||||
createRouter(app => {
|
||||
app.get(
|
||||
'*',
|
||||
validatePackageURL,
|
||||
validatePackageName,
|
||||
validateQuery,
|
||||
fetchPackage,
|
||||
findFile,
|
||||
serveMetadata
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
app.use(
|
||||
'/_module',
|
||||
createRouter(app => {
|
||||
app.get(
|
||||
'*',
|
||||
validatePackageURL,
|
||||
validatePackageName,
|
||||
validateQuery,
|
||||
fetchPackage,
|
||||
findFile,
|
||||
serveModule
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
app.get(
|
||||
'*',
|
||||
validatePackageURL,
|
||||
|
|
Loading…
Reference in New Issue