-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reloading API * Rename env files * undo changes to test docker file * reloader fiel * fix import * Make tests work with most recent substrate contracts node. Fix CaptchaEvent model creation * Update package-lock.json * Use new error type * Set default provider port to 9229
- Loading branch information
Showing
17 changed files
with
135 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2021-2024 Prosopo (UK) Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
import { AwaitedProcessedArgs } from './argv.js' | ||
import { KeyringPair } from '@polkadot/keyring/types' | ||
import { LogLevel, getLogger } from '@prosopo/common' | ||
import { ProsopoConfigOutput } from '@prosopo/types' | ||
import { ProviderEnvironment } from '@prosopo/env' | ||
import { Server } from 'node:net' | ||
import { loadEnv } from './env.js' | ||
import { start } from './start.js' | ||
import fs from 'fs' | ||
|
||
const log = getLogger(LogLevel.enum.info, 'CLI') | ||
|
||
export default class ReloadingAPI { | ||
private _envWatcher: any | ||
private _envPath: string | ||
private _config: ProsopoConfigOutput | ||
private _pair: KeyringPair | ||
private _processedArgs: AwaitedProcessedArgs | ||
private api: Server | undefined | ||
|
||
constructor(envPath: string, config: ProsopoConfigOutput, pair: KeyringPair, processedArgs: AwaitedProcessedArgs) { | ||
this._envPath = envPath | ||
this._config = config | ||
this._pair = pair | ||
this._processedArgs = processedArgs | ||
} | ||
|
||
public async start() { | ||
log.info('Starting API') | ||
this._envWatcher = await this._watchEnv() | ||
const env = new ProviderEnvironment(this._config, this._pair) | ||
await env.isReady() | ||
this.api = await start(env) | ||
} | ||
|
||
public async stop() { | ||
log.info('Stopping API') | ||
if (this.api) { | ||
this.api.close() | ||
} | ||
} | ||
|
||
private async _watchEnv() { | ||
return fs.watchFile(this._envPath, async () => { | ||
await this.stop() | ||
loadEnv() | ||
await this.start() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters