mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-05 06:55:13 +01:00
other minor refactorings cleans multiple describes cleans trading setups fixes global setup/teardown converts all beforeAll to beforeEach
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import http from 'http';
|
|
|
|
import TrezorConnect from '@trezor/connect-mobile';
|
|
|
|
export class DeepLinkServer {
|
|
private server?: http.Server;
|
|
readonly port = 8080;
|
|
readonly url = `http://localhost:${this.port}`;
|
|
|
|
async start() {
|
|
if (this.server && this.server.listening) {
|
|
return;
|
|
}
|
|
|
|
await new Promise<void>(resolve => {
|
|
this.server = http.createServer((req, res) => {
|
|
if (req.url) {
|
|
const url = new URL(req.url, this.url);
|
|
TrezorConnect.handleDeeplink(url.href);
|
|
res.statusCode = 200;
|
|
res.setHeader('Content-Type', 'text/plain');
|
|
res.end('Callback URL received successfully!\n');
|
|
}
|
|
});
|
|
|
|
this.server.listen(this.port, 'localhost', () => {
|
|
// eslint-disable-next-line no-console
|
|
console.info(`Server running at ${this.url}`);
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
|
|
async stop(): Promise<void> {
|
|
if (!this.server) return;
|
|
|
|
await new Promise<void>(resolve => {
|
|
this.server!.close(() => resolve());
|
|
this.server!.closeAllConnections();
|
|
});
|
|
|
|
this.server = undefined;
|
|
}
|
|
}
|