Can I Add Custom MIME Types in server.json?

When I try to load a file with the extension .webmanifest when using the built-in web server Commandbox uses (Undertow), I get a 404 error. I suspect this is because Undertow by default doesn’t recognize the .webmanifest file extension or MIME type. I had a similar problem with IIS which was fixable by adding a custom MIME type to the configuration.

Is there an easy way to add custom MIME types to Undertow, perhaps via the server.json file? I scanned the Ortusbooks documentation and didn’t find anything.

The list of valid extensions comes from CommandBox and you can add additional ones here:

https://commandbox.ortusbooks.com/embedded-server/configuring-your-server/server-rules/allowed-static-files

Brilliant! Thanks, @bdw429s. I was searching the docs using the wrong terms.

Here’s what a sample server.json file might look like with the webmanifest extension added:

{
    "web":{
        "rewrites":{
            "enable":"true"
        },
        "allowedExt": "webmanifest"
    },
    "app":{
        "cfengine":"lucee"
    },
    "name":"my-app"
}

I understand that-- I’ve had hard times finding things before because I didn’t know what the feature was called, etc.

The whitelist of allowed extensions is new in the most recent versions of CommandBox. it was in response to some security issues and was the only fail safe to ensure undertow was never tricked into serving up files we didn’t want it to.

1 Like