Add support for a default index page
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>
|
||||
@@ -22,19 +22,33 @@ function getHref(entry) {
|
||||
|
||||
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) {
|
||||
return () => {
|
||||
const items = [];
|
||||
for (const key in config.entry) {
|
||||
const href = getHref(config.entry[key]);
|
||||
items.push(`<li><a href="${href}">${href}</a></li>`);
|
||||
// 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));
|
||||
}
|
||||
const markup = `<!DOCTYPE html><body><ul>${items.join('')}</ul></body>`;
|
||||
|
||||
res.writeHead(404, {
|
||||
'Content-Type': 'text/html'
|
||||
});
|
||||
res.end(markup);
|
||||
// fall back to a listing of all cases
|
||||
indexHandler(req, res);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user