Don't think passThrough works as expected
Reading the documentation and browsing in issues here (like https://github.com/tes/compoxure/issues/102), it's stated that you have to configure a backend in such a way (as an example if you want to not parse javascript AND html):
"backend": [
{
"pattern": "/assets.*",
"dontPassUrl": false,
"passThrough": true,
"contentTypes": [
"application/javascript",
"html"
],
"target":"{{server:fragments}}"
}
]
Unfortunately this doesn't work because in mediatypes.js the contentTypes is sorted by the negotiator module (in line 8) and only the first occurence of the array is returned (in line 24) as the "accepted" type for further processing: in this case 'html', instead of 'application/javascript'
https://github.com/tes/compoxure/blob/1a6732e65ea32905a17004efff3ee63bcbd2dc8c/src/middleware/mediatypes.js#L8-L24
But the real problem is in the passthrough.js middleware, lines 12-14: because req.contentType has been set to 'html', any request for a js file is parsed, even if it shouldn't.
https://github.com/tes/compoxure/blob/1a6732e65ea32905a17004efff3ee63bcbd2dc8c/src/middleware/passthrough.js#L8-L16
Another bad side effect of the lines 12-14 is that there's no way to passTrough plain html. So, the only way to make it works is to remove the second contentType in the configuration:
"backend": [
{
"pattern": "/assets.*",
"dontPassUrl": false,
"passThrough": true,
"contentTypes": [
"application/javascript"
],
"target":"{{server:fragments}}"
}
]
This has the "nice" side effect to let any content type, even html, passThrough as well, which was my initial goal. My suggestion is to let just the code in mediatypes.js decide if the contentType is allowed or not and then remove lines 12-14 altogether from passtrough.js. If there's agreement on that I can test it and create a PR.