Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Gitmingshao opened this issue Jun 9, 2023 · 3 comments
Open

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

Gitmingshao opened this issue Jun 9, 2023 · 3 comments

Comments

@Gitmingshao
Copy link

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

@DHGHH
Copy link

DHGHH commented Aug 14, 2023

@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
    }
}

@Cqwert123
Copy link

我的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.

@longphandev
Copy link

longphandev commented Jan 17, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants