text: require("dotenv").config();
  
  const fs = require("fs");
  
  const express = require("express");
  const app = express();
  
  const fetch = require("node-fetch");
  
  const failoverDomain = "https://Xondalf.kirondevcoder.repl.co";
  
  app.get("/ping", function(req, res) {
  	res.sendStatus(200);
  });
  
  console.log("Is main host: " + global.isMainHost);
  
  if (global.isMainHost) {
  	// Is main host
  
  	async function exitHandler(options, exitCode) {
  		// if (options != {}) console.error(options);
  		if (exitCode != 0) console.error(exitCode);
  
  		if (exitCode != 0) {
  			// Notify failover host to start
  			await fetch(failoverDomain + "/start");
  			console.log("Sent request to start.");
  		}
  		process.exit();
  	}
  
  	function startHandler() {
  		// Notify failover host that it can rest
  		fetch(failoverDomain + "/stop");
  		console.log("Sent request to stop.");
  	}
  
  	startHandler();
  
  	process.on("exit", exitHandler.bind(null, {}));
  	process.on("SIGINT", exitHandler.bind(null, {}));
  	process.on("SIGUSR1", exitHandler.bind(null, {}));
  	process.on("SIGUSR2", exitHandler.bind(null, {}));
  	process.on("uncaughtException", exitHandler.bind(null, {}));
  } else {
  	// Is failover host
  
  	app.get("/start", async function(req, res) {
  		res.sendStatus(200);
  		global.bod_shouldHandleEvents = true;
  		console.log("Got request from main host to start.");
  
  		fs.writeFile(".failoverData", "true", function (err) {
  			if (err) return console.error(err);
  		});
  	});
  
  	app.get("/stop", async function(req, res) {
  		res.sendStatus(200);
  		global.bod_shouldHandleEvents = false;
  		console.log("Got request from main host to stop.");
  
  		fs.writeFile(".failoverData", "false", function (err) {
  			if (err) return console.error(err);
  		});
  	});
  }
  
  app.listen(8000, function() {
  	console.log("Running webserver.");
  });