Merge pull request #8904 from tschaub/default-index
Add support for a default index page in the rendering tests
This commit is contained in:
@@ -1,22 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<style>
|
|
||||||
html, body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
#map {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="map"></div>
|
|
||||||
<script src="main.js"></script>
|
|
||||||
</body>
|
|
||||||
</script>
|
|
||||||
</html>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<style>
|
|
||||||
html, body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
#map {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="map"></div>
|
|
||||||
<script src="main.js"></script>
|
|
||||||
</body>
|
|
||||||
</script>
|
|
||||||
</html>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<style>
|
|
||||||
html, body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
#map {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="map"></div>
|
|
||||||
<script src="main.js"></script>
|
|
||||||
</body>
|
|
||||||
</script>
|
|
||||||
</html>
|
|
||||||
+23
-9
@@ -22,19 +22,33 @@ function getHref(entry) {
|
|||||||
|
|
||||||
const staticHandler = serveStatic(__dirname);
|
const staticHandler = serveStatic(__dirname);
|
||||||
|
|
||||||
|
const defaultHandler = serveStatic(path.join(__dirname, 'default'));
|
||||||
|
|
||||||
|
function indexHandler(req, res) {
|
||||||
|
const items = [];
|
||||||
|
for (const key in config.entry) {
|
||||||
|
const href = getHref(config.entry[key]);
|
||||||
|
items.push(`<li><a href="${href}">${href}</a></li>`);
|
||||||
|
}
|
||||||
|
const markup = `<!DOCTYPE html><body><ul>${items.join('')}</ul></body>`;
|
||||||
|
|
||||||
|
res.writeHead(404, {
|
||||||
|
'Content-Type': 'text/html'
|
||||||
|
});
|
||||||
|
res.end(markup);
|
||||||
|
}
|
||||||
|
|
||||||
function notFound(req, res) {
|
function notFound(req, res) {
|
||||||
return () => {
|
return () => {
|
||||||
const items = [];
|
// first, try the default directory
|
||||||
for (const key in config.entry) {
|
if (req.url.match(/^\/cases\/[^\/]+\/(index.html)?$/)) {
|
||||||
const href = getHref(config.entry[key]);
|
// request for a case index file, and file not found, use default
|
||||||
items.push(`<li><a href="${href}">${href}</a></li>`);
|
req.url = '/index.html';
|
||||||
|
return defaultHandler(req, res, () => indexHandler(req, res));
|
||||||
}
|
}
|
||||||
const markup = `<!DOCTYPE html><body><ul>${items.join('')}</ul></body>`;
|
|
||||||
|
|
||||||
res.writeHead(404, {
|
// fall back to a listing of all cases
|
||||||
'Content-Type': 'text/html'
|
indexHandler(req, res);
|
||||||
});
|
|
||||||
res.end(markup);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user