美文网首页
Tomcat中配置mime类型

Tomcat中配置mime类型

作者: 盼旺 | 来源:发表于2019-12-10 11:56 被阅读0次

解决问题

Uncaught (in promise) TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

本地Tomcat

在springboot内嵌的Tomcat

在Spring启动中,您可以使用此自定义程序自定义servlet容器,并在其中添加新的mimetypes.
package com.example.wasmdemo.config;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.MimeMappings;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;

@Component
public class ServletCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
    @Override
    public void customize(TomcatServletWebServerFactory factory) {
        MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
        mappings.add("wasm", "application/wasm");
        factory.setMimeMappings(mappings);
    }
}

相关文章

网友评论

      本文标题:Tomcat中配置mime类型

      本文链接:https://www.haomeiwen.com/subject/lvwwgctx.html