function create_http_server(assets, host_psp) {
    return async function(request, response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Request-Method", "*");
        response.setHeader("Access-Control-Allow-Methods", "OPTIONS,GET");
        response.setHeader("Access-Control-Allow-Headers", "*");
        let url = request.url;
        if (url === "/") {
            url = "/index.html";
        }
        let extname = path.extname(url);
        let contentType = CONTENT_TYPES[extname] || "text/html";
        try {
            for (let rootDir of assets) {
                let filePath = rootDir + url;
                let content = await read_promise(filePath);
                if (typeof content !== "undefined") {
                    console.log(`200 ${url}`);
                    response.writeHead(200, {"Content-Type": contentType});
                    response.end(content, extname === ".arrow" ? "user-defined" : "utf-8");
                    return;
                }
            }
            if (host_psp || typeof host_psp === "undefined") {
                for (let rootDir of DEFAULT_ASSETS) {
                    try {
                        let paths = RESOLVER.paths(rootDir + url);
                        paths = [...paths, ...assets.map(x => path.join(x, "node_modules")), LOCAL_PATH];
                        let filePath = RESOLVER(rootDir + url, {paths});
                        let content = await read_promise(filePath);
                        if (typeof content !== "undefined") {
                            console.log(`200 ${url}`);
                            response.writeHead(200, {"Content-Type": contentType});
                            response.end(content, extname === ".arrow" ? "user-defined" : "utf-8");
                            return;
                        }
                    } catch (e) {}
                }
            }
            console.error(`404 ${url}`);
            response.writeHead(404);
            response.end("", "utf-8");
        } catch (error) {
            if (error.code !== "ENOENT") {
                console.error(`500 ${url}`);
                response.writeHead(500);
                response.end("", "utf-8");
            }
        }
    };
}
/**
 * Host a Perspective server that hosts data, code files, etc.
 */
Host a Perspective server that hosts data, code files, etc.
Host a Perspective server that hosts data code files etc .
function create_http_server(assets, host_psp) {
    return async function(request, response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Request-Method", "*");
        response.setHeader("Access-Control-Allow-Methods", "OPTIONS,GET");
        response.setHeader("Access-Control-Allow-Headers", "*");
        let url = request.url;
        if (url === "/") {
            url = "/index.html";
        }
        let extname = path.extname(url);
        let contentType = CONTENT_TYPES[extname] || "text/html";
        try {
            for (let rootDir of assets) {
                let filePath = rootDir + url;
                let content = await read_promise(filePath);
                if (typeof content !== "undefined") {
                    console.log(`200 ${url}`);
                    response.writeHead(200, {"Content-Type": contentType});
                    response.end(content, extname === ".arrow" ? "user-defined" : "utf-8");
                    return;
                }
            }
            if (host_psp || typeof host_psp === "undefined") {
                for (let rootDir of DEFAULT_ASSETS) {
                    try {
                        let paths = RESOLVER.paths(rootDir + url);
                        paths = [...paths, ...assets.map(x => path.join(x, "node_modules")), LOCAL_PATH];
                        let filePath = RESOLVER(rootDir + url, {paths});
                        let content = await read_promise(filePath);
                        if (typeof content !== "undefined") {
                            console.log(`200 ${url}`);
                            response.writeHead(200, {"Content-Type": contentType});
                            response.end(content, extname === ".arrow" ? "user-defined" : "utf-8");
                            return;
                        }
                    } catch (e) {}
                }
            }
            console.error(`404 ${url}`);
            response.writeHead(404);
            response.end("", "utf-8");
        } catch (error) {
            if (error.code !== "ENOENT") {
                console.error(`500 ${url}`);
                response.writeHead(500);
                response.end("", "utf-8");
            }
        }
    };
}
function create_http_server ( assets , host_psp ) { return async function ( request , response ) { response . setHeader ( "Access-Control-Allow-Origin" , "*" ) ; response . setHeader ( "Access-Control-Request-Method" , "*" ) ; response . setHeader ( "Access-Control-Allow-Methods" , "OPTIONS,GET" ) ; response . setHeader ( "Access-Control-Allow-Headers" , "*" ) ; let url = request . url ; if ( url === "/" ) { url = "/index.html" ; } let extname = path . extname ( url ) ; let contentType = CONTENT_TYPES [ extname ] || "text/html" ; try { for ( let rootDir of assets ) { let filePath = rootDir + url ; let content = await read_promise ( filePath ) ; if ( typeof content !== "undefined" ) { console . log ( ` ${ url } ` ) ; response . writeHead ( 200 , { "Content-Type" : contentType } ) ; response . end ( content , extname === ".arrow" ? "user-defined" : "utf-8" ) ; return ; } } if ( host_psp || typeof host_psp === "undefined" ) { for ( let rootDir of DEFAULT_ASSETS ) { try { let paths = RESOLVER . paths ( rootDir + url ) ; paths = [ ... paths , ... assets . map ( x => path . join ( x , "node_modules" ) ) , LOCAL_PATH ] ; let filePath = RESOLVER ( rootDir + url , { paths } ) ; let content = await read_promise ( filePath ) ; if ( typeof content !== "undefined" ) { console . log ( ` ${ url } ` ) ; response . writeHead ( 200 , { "Content-Type" : contentType } ) ; response . end ( content , extname === ".arrow" ? "user-defined" : "utf-8" ) ; return ; } } catch ( e ) { } } } console . error ( ` ${ url } ` ) ; response . writeHead ( 404 ) ; response . end ( "" , "utf-8" ) ; } catch ( error ) { if ( error . code !== "ENOENT" ) { console . error ( ` ${ url } ` ) ; response . writeHead ( 500 ) ; response . end ( "" , "utf-8" ) ; } } } ; }
Host a Perspective server that hosts data, code files, etc.
Host a Perspective server that hosts data code files etc .