2 Commits

4 changed files with 80 additions and 35 deletions
Split View
  1. +29
    -0
      public/static/404.html
  2. +4
    -0
      public/static/index.css
  3. +5
    -0
      src/routes.ts
  4. +42
    -35
      src/util/config.ts

+ 29
- 0
public/static/404.html View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>Page not found - AO Coverage</title>
<link rel="stylesheet" type="text/css" href="/static/index.css" />
</head>
<body>
<div id="top-half">
<div id="container">
<div id="logo"><img src="/favicon.ico" alt="logo" /></div>
<h1 id="tagline">404</h1>
</div>
</div>
<div id="bottom-half">
<div id="container">
<div id="smallcontent">
<p>Oops! The page you are looking for does not exist.</p>
<p><a href="/">Visit the front page</a></p>
</div>
</div>
</div>
</body>
</html>

+ 4
- 0
public/static/index.css View File

@ -39,6 +39,10 @@ div#content p {
padding: 0 10px;
}
div#smallcontent p {
text-align: center;
}
.code-container-container {
margin: 24px;
}


+ 5
- 0
src/routes.ts View File

@ -217,5 +217,10 @@ export default (metadata: Metadata): Router => {
retrieveFile(res, identity, "index.html");
});
router.use((_, res) => {
res.status(404);
res.sendFile(path.join(__dirname, "..", "public", "static", "404.html"));
});
return router;
};

+ 42
- 35
src/util/config.ts View File

@ -37,7 +37,7 @@ export const persistTemplate = async (input: Template): Promise<void> => {
process.exit(1);
}
// if the output file exists, then we are fine with continuing without
logger.warning(
logger.warn(
"Could not generate '%s' from template file, but file already exists: %s",
input.outputFile,
err1
@ -50,43 +50,50 @@ const TARGET_URL = process.env.TARGET_URL ?? "http://localhost:3000";
const HOST_DIR = configOrError("HOST_DIR");
export const handleStartup = async (): Promise<MongoClient> => {
await fs.promises.access(HOST_DIR, fs.constants.R_OK | fs.constants.W_OK);
if (!path.isAbsolute(HOST_DIR)) {
logger.error("HOST_DIR must be an absolute path");
process.exit(1);
}
const mongo = await new MongoClient(MONGO_URI, { useUnifiedTopology: true })
.connect()
.catch((err: MongoError) => {
logger.error(err.message ?? "Unable to connect to database");
try {
await fs.promises.access(HOST_DIR, fs.constants.R_OK | fs.constants.W_OK);
if (!path.isAbsolute(HOST_DIR)) {
logger.error("HOST_DIR must be an absolute path");
process.exit(1);
});
}
const mongo = await new MongoClient(MONGO_URI, { useUnifiedTopology: true })
.connect()
.catch((err: MongoError) => {
logger.error(err.message ?? "Unable to connect to database");
process.exit(1);
});
await persistTemplate({
inputFile: path.join(
__dirname,
"..",
"public",
"templates",
"bash.template"
),
outputFile: path.join(HOST_DIR, "bash"),
context: { TARGET_URL }
} as Template);
await persistTemplate({
inputFile: path.join(
__dirname,
"..",
"public",
"templates",
"index.html.template"
),
outputFile: path.join(HOST_DIR, "index.html"),
context: { TARGET_URL }
} as Template);
await persistTemplate({
inputFile: path.join(
__dirname,
"..",
"..",
"public",
"templates",
"bash.template"
),
outputFile: path.join(HOST_DIR, "bash"),
context: { TARGET_URL }
} as Template);
await persistTemplate({
inputFile: path.join(
__dirname,
"..",
"..",
"public",
"templates",
"index.html.template"
),
outputFile: path.join(HOST_DIR, "index.html"),
context: { TARGET_URL }
} as Template);
return mongo;
return mongo;
} catch (err) {
logger.error("Error occurred during startup: %s", err);
process.exit(1);
}
};
export const handleShutdown = (mongo: MongoClient, server: Server) => (


Loading…
Cancel
Save