import { getLocal , Mockttp } from 'mockttp' ; import { HtkConfig } from './config' ; export class HideWarningServer { constructor ( private config ) { } private server : Mockttp = getLocal ( ) ; public completedPromise = new Promise < void > ( ( resolve ) => { this . server . on ( 'request' , ( req ) => { if ( req . url . includes ( 'hide-warning' ) ) { resolve ( ) ; } } ) ; } ) ; async start ( targetUrl ) { await this . server . start ( ) ; await this . server . get ( '/hide-warning' ) . thenReply ( 200 , `
            <html>
                <title>HTTP Toolkit Warning Fix</title>
                <meta charset="UTF-8" />
                <style>
                    body { background-color: #d8e2e6; }
                </style>
                <script>
                    const targetUrl = ${ JSON . stringify ( targetUrl ) };
                    window.open(targetUrl, '_blank');
                    window.close();
                </script>
                <body>
                    This page should disappear momentarily. If it doesn't, click
                    <a href="${ targetUrl }">this link</a>
                </body>
            </html>
        ` , { "content-type" : "text/html" } ) ; } get host ( ) : string { return this . server ! . url . replace ( 'https://' , '' ) ; } get hideWarningUrl ( ) : string { return this . server . url . replace ( /\/?$/ , '/hide-warning' ) ; } async stop ( ) { await this . server . stop ( ) ; } }