test/index.js
/*      outcome/
 * Launch a HTTP site that serves the testing HTML interface (test.html)
 * and handles aip calls and SSE requests from that page.
 */
outcome
Launch a HTTP site that serves the testing HTML interface (test.html)
and handles aip calls and SSE requests from that page.
outcome Launch a HTTP site that serves the testing HTML interface ( test . html ) and handles aip calls and SSE requests from that page .
function serveTestSite(cfg) {
    http.createServer((req, res) => {
        if(req.url == '/') send_test_html_1(req, res)
        else if(req.url.startsWith("/kore-test/")) callKoreFns(req, res)
        else if(req.url == '/test-sse') setSSERequestor(req, res)
        else send_req_file_1(req, res)
    }).listen(cfg.PORT, () => {
        console.log(`Test server running on ${cfg.PORT}`)
    })
    function send_test_html_1(req, res) {
        let testInterface = path.join(__dirname, 'test.html')
        let stream = fs.createReadStream(testInterface)
        stream.pipe(res)
        stream.on('error', (err) => {
            console.log(e)
            sendErr(500, `Unexpected Error: No 'test.html' found!`, res)
        })
    }
    function send_req_file_1(req, res) {
        let mt = {
            css: 'text/css',
        }
        let p = path.join(__dirname, req.url)
        let type_ = path.extname(p).substring(1)
        let stream = fs.createReadStream(p)
        if(mt[type_]) res.setHeader('Content-Type', mt[type_])
        stream.pipe(res)
        stream.on('error', (err) => {
            console.log(err)
            sendErr(400, `'${req.url}' not found`, res)
        })
    }
}
function serveTestSite ( cfg ) { http . createServer ( ( req , res ) => { if ( req . url == '/' ) send_test_html_1 ( req , res ) else if ( req . url . startsWith ( "/kore-test/" ) ) callKoreFns ( req , res ) else if ( req . url == '/test-sse' ) setSSERequestor ( req , res ) else send_req_file_1 ( req , res ) } ) . listen ( cfg . PORT , ( ) => { console . log ( ` ${ cfg . PORT } ` ) } ) function send_test_html_1 ( req , res ) { let testInterface = path . join ( __dirname , 'test.html' ) let stream = fs . createReadStream ( testInterface ) stream . pipe ( res ) stream . on ( 'error' , ( err ) => { console . log ( e ) sendErr ( 500 , ` ` , res ) } ) } function send_req_file_1 ( req , res ) { let mt = { css : 'text/css' , } let p = path . join ( __dirname , req . url ) let type_ = path . extname ( p ) . substring ( 1 ) let stream = fs . createReadStream ( p ) if ( mt [ type_ ] ) res . setHeader ( 'Content-Type' , mt [ type_ ] ) stream . pipe ( res ) stream . on ( 'error' , ( err ) => { console . log ( err ) sendErr ( 400 , ` ${ req . url } ` , res ) } ) } }
outcome
 Launch a HTTP site that serves the testing HTML interface (test.html)
 and handles aip calls and SSE requests from that page.
outcome Launch a HTTP site that serves the testing HTML interface ( test . html ) and handles aip calls and SSE requests from that page .