AndServer icon indicating copy to clipboard operation
AndServer copied to clipboard

低版本手机报错application/octet-stream

Open Gitmingshao opened this issue 1 year ago • 3 comments

Failed to load module script: The server responded with a non-JavaScript MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec

Gitmingshao avatar Jun 09 '23 08:06 Gitmingshao

@Gitmingshao 加个HandlerInterceptor

@Interceptor
class LoggerInterceptor : HandlerInterceptor {

    companion object {
        private const val TAG = "WebLogger"
    }

    override fun onIntercept(
        request: HttpRequest,
        respons: HttpResponse,
        handler: RequestHandler,
    ): Boolean {
        val httpPath = request.path
        val method = request.method
        val valueMap = request.parameter
        RLog.v(TAG, "Path:$httpPath, Method:${method.value()}, Param:${Gson().toJson(valueMap)}")
        if (httpPath.endsWith(".css")) {
            respons.setHeader("Content-Type", "text/css; charset=UTF-8")
        } else if (httpPath.endsWith(".js")) {
            respons.setHeader("Content-Type", "application/javascript; charset=UTF-8")
        }
        return false
    }
}

DHGHH avatar Aug 14 '23 23:08 DHGHH

我的2.1.10加上了,还是提示错误 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.

Cqwert123 avatar Dec 13 '23 12:12 Cqwert123

@Gitmingshao 加个HandlerInterceptor

@interceptor class LoggerInterceptor : HandlerInterceptor {

companion object {
    private const val TAG = "WebLogger"
}

override fun onIntercept(
    request: HttpRequest,
    respons: HttpResponse,
    handler: RequestHandler,
): Boolean {
    val httpPath = request.path
    val method = request.method
    val valueMap = request.parameter
    RLog.v(TAG, "Path:$httpPath, Method:${method.value()}, Param:${Gson().toJson(valueMap)}")
    if (httpPath.endsWith(".css")) {
        respons.setHeader("Content-Type", "text/css; charset=UTF-8")
    } else if (httpPath.endsWith(".js")) {
        respons.setHeader("Content-Type", "application/javascript; charset=UTF-8")
    }
    return false
}

}

totally works. many thanks

pnlgcoding avatar Jan 17 '24 07:01 pnlgcoding