提问人:Lee Probert 提问时间:11/7/2023 更新时间:11/7/2023 访问量:57
如何为 Unity WebGL Build 配置 Node Express 服务器
How to configure Node Express server for Unity WebGL Build
问:
Unity 使用 Brotli 压缩和 Web 汇编文件发布其 WebGL 构建。我注意到,如果您使用生产版本,则文件被命名并且 - 这似乎是压缩的 Brotli 压缩文件。public.wasm.unityweb
public.data.unityweb
这是我用于添加标头和内容类型的节点快速代码:
const app = express();
app.use(express.static(path.join(__dirname, 'public'), {
setHeaders: function(res, path) {
if(path.endsWith(".unityweb") || path.endsWith(".br")){
res.set("Content-Encoding", "br");
}else if(path.endsWith(".gzip")){
res.set("Content-Encoding", "gzip");
}
if(path.endsWith(".wasm")){
res.set("Content-Type", "application/wasm");
}
if(path.endsWith(".data")){
res.set("Content-Type", "application/octet-stream");
}
}
}));
我在浏览器中收到来自Unity的警告,指出:
public.loader.js:17 WebAssembly streaming compilation failed! This can happen for example if "Content-Encoding" HTTP header is incorrectly enabled on the server for file Build/public.wasm, but the file is not pre-compressed on disk (or vice versa). Check the Network tab in browser Devtools to debug server header configuration.
任何人都可以帮我为这些文件配置服务器吗?我在 Google App Engine 上托管它。
答: 暂无答案
评论
public.data
public.wasm
res.set("Content-Encoding", "br");