Tomcat中配置mime类型

2019-12-10  本文已影响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);
    }
}

上一篇 下一篇

猜你喜欢

热点阅读