aboutsummaryrefslogtreecommitdiff
path: root/src/server/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/index.ts')
-rw-r--r--src/server/index.ts41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/server/index.ts b/src/server/index.ts
index 551ce3898..42b4f7ff2 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -10,7 +10,7 @@ import initializeServer from './Initialization';
import RouteManager, { Method, _success, _permission_denied, _error, _invalid, OnUnauthenticated } from './RouteManager';
import * as qs from 'query-string';
import UtilManager from './ApiManagers/UtilManager';
-import SearchManager from './ApiManagers/SearchManager';
+import { SearchManager, SolrManager } from './ApiManagers/SearchManager';
import UserManager from './ApiManagers/UserManager';
import { WebSocket } from './Websocket/Websocket';
import DownloadManager from './ApiManagers/DownloadManager';
@@ -21,18 +21,48 @@ import UploadManager from "./ApiManagers/UploadManager";
import { log_execution } from "./ActionUtilities";
import GeneralGoogleManager from "./ApiManagers/GeneralGoogleManager";
import GooglePhotosManager from "./ApiManagers/GooglePhotosManager";
-import DiagnosticManager from "./ApiManagers/DiagnosticManager";
import { yellow } from "colors";
export const publicDirectory = path.resolve(__dirname, "public");
export const filesDirectory = path.resolve(publicDirectory, "files");
+export const ExitHandlers = new Array<() => void>();
+
/**
* These are the functions run before the server starts
* listening. Anything that must be complete
* before clients can access the server should be run or awaited here.
*/
async function preliminaryFunctions() {
+ process.on('SIGINT', () => {
+ const { stdin, stdout, stderr } = process;
+ stdin.resume();
+ stdout.resume();
+ stderr.resume();
+ ExitHandlers.forEach(handler => handler());
+ console.log("Okay, now we're done...");
+ // process.exit(0);
+ });
+
+ (process as any).on('cleanup', () => {
+ console.log("CLEANING UP!");
+ });
+
+ process.on('exit', function () {
+ (process.emit as Function)('cleanup');
+ });
+
+ //catch uncaught exceptions, trace, then exit normally
+ process.on('uncaughtException', function (e) {
+ console.log('Uncaught Exception...');
+ process.exit(99);
+ });
+ process.on('unhandledRejection', function (e) {
+ console.log('Unhandled Rejection...');
+ process.exit(99);
+ });
+
+ await SolrManager.initializeSolr();
await GoogleCredentialsLoader.loadCredentials();
GoogleApiServerUtils.processProjectCredentials();
await DashUploadUtils.buildFileDirectories();
@@ -57,7 +87,6 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }:
new UserManager(),
new UploadManager(),
new DownloadManager(),
- new DiagnosticManager(),
new SearchManager(),
new PDFManager(),
new DeleteManager(),
@@ -79,6 +108,12 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }:
onValidation: ({ res }) => res.redirect("/home")
});
+ addSupervisedRoute({
+ method: Method.GET,
+ subscription: "/serverHeartbeat",
+ onValidation: ({ res }) => res.send(true)
+ });
+
const serve: OnUnauthenticated = ({ req, res }) => {
const detector = new mobileDetect(req.headers['user-agent'] || "");
const filename = detector.mobile() !== null ? 'mobile/image.html' : 'index.html';