Skip to content

Commit 4d05c4b

Browse files
committed
can define API_URL environment variable to get templates info at some other API server
1 parent 8eccbb3 commit 4d05c4b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/myst-cli/src/session/session.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if (!globalThis.fetch) {
3939
}
4040

4141
const CONFIG_FILES = ['myst.yml'];
42-
const API_URL = 'https://api.mystmd.org';
42+
const DEFAULT_API_URL = 'https://api.mystmd.org';
4343
const NPM_COMMAND = 'npm i -g mystmd@latest';
4444
const PIP_COMMAND = 'pip install -U mystmd';
4545
const LOCALHOSTS = ['localhost', '127.0.0.1', '::1'];
@@ -98,7 +98,11 @@ export class Session implements ISession {
9898
}
9999

100100
constructor(opts: { logger?: Logger; doiLimiter?: Limit; configFiles?: string[] } = {}) {
101-
this.API_URL = API_URL;
101+
// use env variable if set
102+
this.API_URL = process.env.API_URL ?? DEFAULT_API_URL;
103+
// trailing slashes will cause issues
104+
this.API_URL = this.API_URL.replace(/\/+$/, '');
105+
console.log(`building myst-cli session with API URL: ${this.API_URL}`);
102106
this.configFiles = (opts.configFiles ? opts.configFiles : CONFIG_FILES).slice();
103107
this.$logger = opts.logger ?? chalkLogger(LogLevel.info, process.cwd());
104108
this.doiLimiter = opts.doiLimiter ?? pLimit(3);

packages/myst-templates/src/session.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import type { RequestInfo, RequestInit, Response } from 'node-fetch';
77
const DEFAULT_API_URL = 'https://api.mystmd.org';
88

99
export class Session implements ISession {
10-
API_URL = process.env.API_URL ?? DEFAULT_API_URL;
10+
API_URL: string;
1111
log: Logger;
1212
constructor(opts?: { logger?: Logger }) {
13+
// use env variable if set
14+
this.API_URL = process.env.API_URL ?? DEFAULT_API_URL;
15+
// trailing slashes will cause issues
16+
this.API_URL = this.API_URL.replace(/\/+$/, '');
1317
this.log = opts?.logger ?? chalkLogger(LogLevel.debug);
1418
}
1519

0 commit comments

Comments
 (0)