Skip to content

Commit

Permalink
Split web service enable into its own setting
Browse files Browse the repository at this point in the history
Fixes #265
  • Loading branch information
neilenns committed Jun 18, 2020
1 parent a29bd9d commit 189e0ea
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## Unreleased

- The internal web server can now be enabled independently from annotated images using the
`enableWebServer` setting. It's off by default, and enabled automatically when `enableAnnotations` is on for backwards compatibility reasons. Resolves [issue 265](https://github.com/danecreekphotography/node-deepstackai-trigger/issues/265).

## Version 3.0.0

### Breaking changes
Expand Down
4 changes: 4 additions & 0 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ITelegramManagerConfigJson from "./handlers/telegramManager/ITelegramMana
export let awaitWriteFinish: boolean;
export let deepstackUri: string;
export let enableAnnotations: boolean;
export let enableWebServer: boolean;
export let mqtt: IMqttManagerConfigJson;
export let port: number;
export let processExistingImages: boolean;
Expand Down Expand Up @@ -52,6 +53,9 @@ export function loadConfiguration(configFilePaths: string[]): void {
awaitWriteFinish = settingsConfigJson.awaitWriteFinish ?? false;
deepstackUri = settingsConfigJson.deepstackUri;
enableAnnotations = settingsConfigJson.enableAnnotations ?? false;
// For backwards compatibility reasons enableWebServer is automatically true
// when enableAnnotations is true.
enableWebServer = enableAnnotations ? true : settingsConfigJson.enableWebServer ?? false;
mqtt = settingsConfigJson.mqtt;
port = settingsConfigJson.port ?? 4242;
processExistingImages = settingsConfigJson.processExistingImages ?? false;
Expand Down
17 changes: 13 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ async function main() {
);
}

// Initialize the local storage and web server if enabled.
// To make things simpler just enable local storage all the time. It won't
// do anything harmful if it's unused, just the occasional background purge
// that runs.
await LocalStorageManager.initializeStorage();
LocalStorageManager.startBackgroundPurge();

// Purely for logging information.
if (Settings.enableAnnotations) {
log.info("Main", "Annotated images are enabled due to presence of the ENABLE_ANNOTATIONS environment variable.");
await LocalStorageManager.initializeStorage();
LocalStorageManager.startBackgroundPurge();
log.info("Main", "Annotated image generation enabled.");
}

// Enable the web server.
if (Settings.enableWebServer) {
log.info("Main", "Web server enabled.");
WebServer.startApp();
}

Expand Down
6 changes: 6 additions & 0 deletions src/schemas/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
"default": false,
"examples": [true]
},
"enableWebServer": {
"type": "boolean",
"description": "Enables the local web server. Disabled by default.",
"default": false,
"examples": [true]
},
"deepstackUri": {
"type": "string",
"description": "The address of the Deepstack AI processing server.",
Expand Down
1 change: 1 addition & 0 deletions src/types/ISettingsConfigJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default interface ISettingsConfigJson {
awaitWriteFinish?: boolean;
deepstackUri: string;
enableAnnotations?: boolean;
enableWebServer?: boolean;
mqtt?: IMqttManagerConfigJson;
port?: number;
processExistingImages?: boolean;
Expand Down

0 comments on commit 189e0ea

Please sign in to comment.