Provide the proper content-type in wasm sample

This commit is contained in:
Alexander Gorshenev
2019-07-11 22:30:04 +03:00
committed by alexander-gorshenev
parent cde1e43e4a
commit e25ad5eafe
@@ -7,9 +7,14 @@
package sample.html5canvas.httpserver package sample.html5canvas.httpserver
import io.ktor.application.call
import io.ktor.http.ContentType
import io.ktor.http.content.LocalFileContent
import io.ktor.http.content.default import io.ktor.http.content.default
import io.ktor.http.content.files import io.ktor.http.content.files
import io.ktor.http.content.static import io.ktor.http.content.static
import io.ktor.response.respond
import io.ktor.routing.get
import io.ktor.routing.routing import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty import io.ktor.server.netty.Netty
@@ -34,6 +39,16 @@ fun main(args: Array<String>) {
val server = embeddedServer(Netty, 8080) { val server = embeddedServer(Netty, 8080) {
routing { routing {
val wasm = "build/bin/html5Canvas/releaseExecutable/html5Canvas.wasm"
get(wasm) {
// TODO: ktor as of now doesn't know about 'application/wasm'.
// The newer browsers (firefox and chrome at least) don't allow
// 'application/octet-stream' for wasm anymore.
// We provide the proper content type here and,
// at the same time, put it into the ktor database.
// Remove this whole get() clause when ktor fix is available.
call.respond(LocalFileContent(File(wasm), ContentType("application", "wasm")))
}
static("/") { static("/") {
files(contentRoot) files(contentRoot)
default("index.html") default("index.html")