https://kotlinlang.org logo
#ktor
Title
# ktor
j

Jan

07/15/2022, 5:50 PM
whats a good way to access the location hash thing in a html (like: https://test.com/callback#arg=2, everything after #) in ktor? This doesn't seem to work:
Copy code
get("/") {
    call.respondText(ContentType.Text.Html) {
        """
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <title>Supabase In App Authentication</title>
            </head>

            <body>
            <script>
                const pairs = location.hash.substring(1).split("&").map(pair => pair.split("="))
            </script>
            </body>
            </html>
        """.trimIndent()
    }
}
Is there a good way without using templates or something?
Note: I don't wanna access the hash directly in ktor I just want that html to work
if I try that I just see a blank site
Ok nvm the url was just pointing to a html website but its not ending with html so
e

Eric Grimsborn

07/17/2022, 2:45 AM
If you are responding with HTML from your ktor backend you might want to check out
kotlinx.html
https://ktor.io/docs/html-dsl.html#html_response It is not templating but rather a way of writing typesafe html with code. You would have something like this instead
Copy code
call.respondHtml {
    head {
        title("Supabase In App Authentication")
    }
    body {
        script {
            unsafe { // will not escape the text
                +"""const pairs = location.hash.substring(1).split("&").map(pair => pair.split("="))"""
            }
        }
    }
}
2 Views