// Web page retrieval using server-side proxy support to get around CORS restrictions

requirejs(["sanitizeHTML", "vendor/purify"], function(sanitizeHTML, DOMPurify) {

    let content
    
    // const url = "http://kurtz-fernhout.com/"
    const url = "http://pdfernhout.net/"
    
    const crossOriginService = "/api/proxy"
    
    m.request({
        method: "POST",
        url: crossOriginService,
        data: { url },
    }).then((result) => {
        console.log("result", result)
        content = result.content
        m.redraw()
    }).catch((error) => {
        console.log("An error occured:", error)
        content = JSON.stringify(error)
        m.redraw()
    })
    
    Twirlip7.show(() => {
        return m("div", [
            content ?
                // Two examples of ways to sanitize web content for display locally -- but always a bit of a risk to display remote content
                sanitizeHTML.generateSanitizedHTMLForMithrilWithAttributes(m, DOMParser, content, {allowLinks: true, allowImages: true, allowIds: true, baseURL: url})
                // m.trust(DOMPurify.sanitize(content))
                : 
                "loading..."
        ])
    }, { title: url })
})

@@ -78,16 +78,144 @@
 rictions
+%0A// Proxying will only work if using the Twirlip7 server%0A// So, proxy requests won't work if running from GitHub and rawgit.com.
 %0A%0Arequir
@@ -762,29 +762,25 @@
 t = 
-JSON.stringify(
+%22ERROR: %22 + 
 error
-)
 %0A   

Improve error reporting in proxy-web-page.js