Skip to content

Commit

Permalink
feat: Plugsy agent endpoint can be specified using environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Nairn authored and Thomas Nairn committed Aug 11, 2021
1 parent cf74932 commit 6f7ecd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/agent/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const environment = () => ({
loggingLevel: process.env.PLUGSY_LOGGER_LEVEL ?? "info",
localConfigFile: process.env.PLUGSY_LOCAL_CONFIG_FILE ?? "/config.json",
agentEndpoint: process.env.PLUGSY_AGENT_ENDPOINT
});

export type Environment = ReturnType<typeof environment>;
16 changes: 13 additions & 3 deletions packages/agent/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createItemServer,
getConnector,
} from "@plugsy/connectors";
import { filter, map, ReplaySubject, share, tap } from "rxjs";
import { filter, map, of, ReplaySubject, share, switchMap, tap } from "rxjs";
import { Logger } from "winston";
import { agent, AgentConfig } from "./";
import schema from "./config-schema.json";
Expand Down Expand Up @@ -81,7 +81,7 @@ function watchConfig(filePath: string, logger: Logger) {
}

async function startServer() {
const { localConfigFile, loggingLevel } = environment();
const { localConfigFile, loggingLevel, agentEndpoint } = environment();
const logger = createLogger(loggingLevel);
logger.verbose("watchConfig");
const { connectors$, agentConfig$, loggingLevel$ } = watchConfig(
Expand All @@ -106,7 +106,17 @@ async function startServer() {

logger.verbose("initAgent");
const agentSubscription = agent(
agentConfig$,
agentConfig$.pipe(
switchMap((config) => {
return of(
config ?? agentEndpoint
? {
endpoint: agentEndpoint,
}
: undefined
);
})
),
itemServer.connectionData$,
logger
).subscribe();
Expand Down

0 comments on commit 6f7ecd4

Please sign in to comment.