This is the http.js for our backend Real Deal Bridge server. This ensures the correct headers are set when serving Unity WebGL content.
For more information, check out this blog post.
/**
* HTTP Server Settings
* (sails.config.http)
*
* Configuration for the underlying HTTP server in Sails.
* (for additional recommended settings, see `config/env/production.js`)
*
* For more information on configuration, check out:
* https://sailsjs.com/config/http
*/
const express = require('express');
module.exports.http = {
middleware: {
order: [
'cookieParser',
'session',
'unity',
'compress',
'poweredBy',
'skipper',
'router',
'www',
'favicon',
],
//Configure Skipper
skipper: require('skipper')({
maxWaitTimeBeforePassingControlToApp: 1000,
}),
//Configure unity
unity: (function (){
console.log("Initializing Unity middleware");
express.static.mime.define({'application/wasm': ['wasm']});
return function(req, res, next){
if(req.path.endsWith("unityweb") || req.path.endsWith("wasm")){
res.set("Content-Encoding", "gzip");
res.set("Cache-Control", "max-age=0, no-cache, must-revalidate");
res.set("Large-Allocation", "0");
}
if(req.path.endsWith("zip")){
res.set("Cache-Control", "max-age=0, no-cache, must-revalidate");
}
return next();
};
})(),
},
};