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 serveAutoIndexPage from './serveAutoIndexPage';
|
||||||
import serveHTMLModule from './serveHTMLModule';
|
|
||||||
import serveJavaScriptModule from './serveJavaScriptModule';
|
|
||||||
import serveMetadata from './serveMetadata';
|
import serveMetadata from './serveMetadata';
|
||||||
|
import serveModule from './serveModule';
|
||||||
import serveStaticFile from './serveStaticFile';
|
import serveStaticFile from './serveStaticFile';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the file, JSON metadata, or HTML directory listing.
|
* Send the file, JSON metadata, or HTML directory listing.
|
||||||
*/
|
*/
|
||||||
export default function serveFile(req, res) {
|
export default function serveFile(req, res) {
|
||||||
|
// Deprecated.
|
||||||
if (req.query.meta != null) {
|
if (req.query.meta != null) {
|
||||||
return serveMetadata(req, res);
|
return serveMetadata(req, res);
|
||||||
}
|
}
|
||||||
|
@ -16,19 +16,9 @@ export default function serveFile(req, res) {
|
||||||
return serveAutoIndexPage(req, res);
|
return serveAutoIndexPage(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated.
|
||||||
if (req.query.module != null) {
|
if (req.query.module != null) {
|
||||||
if (req.entry.contentType === 'application/javascript') {
|
return serveModule(req, res);
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serveStaticFile(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.
|
* Redirect old URLs that we no longer support.
|
||||||
*/
|
*/
|
||||||
export default function redirectLegacyURLs(req, res, next) {
|
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\//)) {
|
if (req.path.match(/^\/_meta\//)) {
|
||||||
req.query.meta = '';
|
return res.redirect(301, '/_metadata' + req.path.substr(6));
|
||||||
return res.redirect(301, req.path.substr(6) + createSearch(req.query));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Permanently redirect /path?json => /path?meta
|
// Permanently redirect /path?json => /path?meta
|
||||||
if (req.query.json != null) {
|
if (req.query.json != null) {
|
||||||
delete req.query.json;
|
return res.redirect(301, '/_metadata' + req.path);
|
||||||
req.query.meta = '';
|
|
||||||
return res.redirect(301, req.path + createSearch(req.query));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
|
@ -2,8 +2,8 @@ import createSearch from '../utils/createSearch';
|
||||||
|
|
||||||
const knownQueryParams = {
|
const knownQueryParams = {
|
||||||
main: true, // Deprecated, see #63
|
main: true, // Deprecated, see #63
|
||||||
meta: true,
|
meta: true, // Deprecated
|
||||||
module: true
|
module: true // Deprecated
|
||||||
};
|
};
|
||||||
|
|
||||||
function isKnownQueryParam(param) {
|
function isKnownQueryParam(param) {
|
||||||
|
|
|
@ -3,6 +3,8 @@ import express from 'express';
|
||||||
// import serveAuth from './actions/serveAuth';
|
// import serveAuth from './actions/serveAuth';
|
||||||
import serveFile from './actions/serveFile';
|
import serveFile from './actions/serveFile';
|
||||||
import serveMainPage from './actions/serveMainPage';
|
import serveMainPage from './actions/serveMainPage';
|
||||||
|
import serveMetadata from './actions/serveMetadata';
|
||||||
|
import serveModule from './actions/serveModule';
|
||||||
import servePublicKey from './actions/servePublicKey';
|
import servePublicKey from './actions/servePublicKey';
|
||||||
import serveStats from './actions/serveStats';
|
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(
|
app.get(
|
||||||
'*',
|
'*',
|
||||||
validatePackageURL,
|
validatePackageURL,
|
||||||
|
|
Loading…
Reference in New Issue