Merge pull request #8904 from tschaub/default-index

Add support for a default index page in the rendering tests
This commit is contained in:
Tim Schaub
2018-11-10 15:57:24 -07:00
committed by GitHub
5 changed files with 23 additions and 75 deletions
@@ -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>
-22
View File
@@ -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>
+16 -2
View File
@@ -22,8 +22,9 @@ function getHref(entry) {
const staticHandler = serveStatic(__dirname); const staticHandler = serveStatic(__dirname);
function notFound(req, res) { const defaultHandler = serveStatic(path.join(__dirname, 'default'));
return () => {
function indexHandler(req, res) {
const items = []; const items = [];
for (const key in config.entry) { for (const key in config.entry) {
const href = getHref(config.entry[key]); const href = getHref(config.entry[key]);
@@ -35,6 +36,19 @@ function notFound(req, res) {
'Content-Type': 'text/html' 'Content-Type': 'text/html'
}); });
res.end(markup); res.end(markup);
}
function notFound(req, res) {
return () => {
// first, try the default directory
if (req.url.match(/^\/cases\/[^\/]+\/(index.html)?$/)) {
// request for a case index file, and file not found, use default
req.url = '/index.html';
return defaultHandler(req, res, () => indexHandler(req, res));
}
// fall back to a listing of all cases
indexHandler(req, res);
}; };
} }