Added the oasstApiClient global var and init

This commit is contained in:
klotske
2023-01-06 13:44:46 +03:00
parent f5b49a952e
commit 3c330dcd13
4 changed files with 15 additions and 8 deletions
+12 -1
View File
@@ -1,5 +1,10 @@
import { JWT } from "next-auth/jwt";
declare global {
// eslint-disable-next-line no-var
var oasstApiClient: OasstApiClient | undefined;
}
class OasstError {
message: string;
errorCode: number;
@@ -12,7 +17,7 @@ class OasstError {
}
}
export default class OasstApiClient {
export class OasstApiClient {
constructor(private readonly oasstApiUrl: string, private readonly oasstApiKey: string) {}
private async post(path: string, body: any): Promise<any> {
@@ -85,3 +90,9 @@ export default class OasstApiClient {
});
}
}
export const oasstApiClient =
globalThis.oasstApiClient || new OasstApiClient(process.env.FASTAPI_URL, process.env.FASTAPI_KEY);
if (process.env.NODE_ENV !== "production") {
globalThis.oasstApiClient = oasstApiClient;
}