Keep content-type when serving assets from generic package repository
Generic Repository is an amazing feature to enable distribution of assets. The service will unfortunately return a application/octet-stream
content type (as per doc) making it useless for serving build for web.
Current behaviour
The use case is a CSS
and JS
UMD (universal module definition) bundle created in a pipeline, and to be imported directly from within .html
files.
[Chrome] Refused to apply style from 'https://XXXX/api/v4/projects/XXXX/packages/generic/XXXX/latest/styles.css' because its MIME type ('application/octet-stream') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
The same problems also occurs when importing external JS libraries
<html>
<head>
<!-- Import react as peer dependency-->
<script crossorigin src="https://XXXX/api/v4/projects/XXXX/packages/generic/XXXX/latest/index.css"></script>
</head>
</html>
Expected behaviour
Generic repository should keep the content-type
provided at push time
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" \
--header "Content-Type: text/javascript" \
--upload-file dist/umd/index.js \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/XXXX/latest/index.js"'
or, alternatively for backward compatibility, accept an additional X-Gitlab-Content-Type
header (or anything else) to record the delivery content type
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" \
--header "X-Gitlab-Content-Type: text/javascript" \
--upload-file dist/umd/index.js \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/XXXX/latest/index.js"'
The alternative is to rely on third party CDN. Or to deploy a dedicated service to serve raw JS & CSS assets.