diff --git a/main.js b/main.js
index 966fe5c..4e865e8 100755
--- a/main.js
+++ b/main.js
@@ -33,9 +33,9 @@ const asset_types = ['png', 'svg', 'ico', 'webmanifest', 'jpg'];
let ports = [];
// Check parameters for numeric port numbers.
process.argv.forEach(function (val, index, array) {
- console.log("Parameter", index + ':', val, !isNaN(val));
+ console.log(now() + ": Parameter", index + ':', val, !isNaN(val));
if (!isNaN(val)) {
- console.log("Adding Port", val)
+ console.log(now() + ": Adding Port", val)
ports.push(val);
}
});
@@ -96,16 +96,21 @@ function getMIME(extension) {
return mime;
}
+// Print datetime for logging.
+function now() {
+ return new Date().toISOString();
+}
+
/* Code exists inside a main function so that we may use async/await.
*/
async function main() {
- console.log("...Starting Main...");
+ console.log(now() + ": ...Starting Main...");
// Getting dates in Node.js is awful, just use Linux.
const start_datetime = "" + await execSync('date "+%Y-%m-%dT%H:%M:%S%:z"');
const start_datetime_trimmed = start_datetime.trim();
- console.log("Set app to return HTML documents.");
+ console.log(now() + ": Set app to return HTML documents.");
app.use(function (req, res, next) {
res.contentType('text/html');
next();
@@ -114,7 +119,7 @@ async function main() {
/* Loop through all files in the pages subdirectory and add the allowed
// file types into the pages array for automatic router creation.
*/
- console.log("...Starting Main...");
+ console.log(now() + ": ...Starting Pages...");
let ls = await fs.promises.readdir(pages_dir);
if (DEBUG) console.log("DEBUG: Results of ls, ", ls);
for (let file of ls) {
@@ -124,18 +129,19 @@ async function main() {
if (file_types.includes(file_type)) {
if (DEBUG) console.log("DEBUG: Hooray!", file, "is being added.");
pages[file_name] = pages_dir + file;
- console.log(" * Added page", file);
+ console.log(now() + ": * Added page", file);
} else {
if (DEBUG) console.log("DEBUG: ", file, "is not an approved type, skipping.");
}
}
- console.log(" * Pages loaded: ", pages);
+ console.log(now() + ": * Pages loaded: ", pages);
//return; // Stop execution FORTESTING
/* Loop through the assets folder and grab favicons, manifests, etc. and
// allow them to be accessed via the root of the website, such as a favicon
// at 'https://hyperling.com/favicon.ico'. May help with SEO!
*/
+ console.log(now() + ": ...Starting Assets...");
let ls_assets = await fs.promises.readdir(asset_dir);
if (DEBUG) console.log("DEBUG: Results of ls_assets, ", ls_assets);
for (let file of ls_assets) {
@@ -145,12 +151,12 @@ async function main() {
if (asset_types.includes(file_type)) {
if (DEBUG) console.log("DEBUG: Hooray!", file, "is being added.");
assets[file] = asset_dir + file;
- console.log(" * Added asset", file);
+ console.log(now() + ": * Added asset", file);
} else {
if (DEBUG) console.log("DEBUG: ", file, "is not an approved type, skipping.");
}
}
- console.log(" * Assets loaded: ", assets);
+ console.log(now() + ": * Assets loaded: ", assets);
/* Create both an XML and HTML sitemap based on these entries. XML is used for
// bots like SEO scrapers. HTML will be for human users looking for a list of
@@ -212,7 +218,7 @@ async function main() {
Sitemap: https://hyperling.com/sitemap.xml
`;
- console.log("...Adding Routes...");
+ console.log(now() + ": ...Adding Routes...");
let router = express.Router();
/* AUTOMATIC METHOD BASED ON OBJECT/ARRAY OF WEB SCRIPTS
@@ -220,9 +226,9 @@ async function main() {
*/
// TBD/TODO would be great to log this as "DATE: ADDRESS hit ROUTER requesting RESOURCE"
for (let key in pages) {
- console.log(" * Creating router for", key);
+ console.log(now() + ": * Creating router for", key);
router.get("/" + key, async function (req,res) {
- console.log(key, "fulfilling request to", req.socket.remoteAddress, "asking for", req.url);
+ console.log(now() + ":", key, "fulfilling request to", req.socket.remoteAddress, "asking for", req.url);
let html = "" + execSync(pages[key]);
stringsToRemove.forEach(string => {
html = html.replace(string, "");
@@ -233,7 +239,7 @@ async function main() {
/* Append the page to the sitemap variables.
*/
- console.log(" * * Adding to sitemap.xml");
+ console.log(now() + ": * * Adding to sitemap.xml");
sitemap_xml = sitemap_xml + `