incorrect MIME type for Javacript files #3

Closed
opened 2024-08-08 22:11:40 +02:00 by djmil · 3 comments
Owner

For the egui-corcles project, incorrect MIME is returned for *.js files failing the whole Pages flow

Expected:

get https://demo.pages.djmil.dev/egui-circles/egui-circles-4f8030f072449e22.js
Content-Type: application/javascript

Actual:

get https://demo.pages.djmil.dev/egui-circles/egui-circles-4f8030f072449e22.js
Content-Type: text/plain; charset=utf-8

For the [egui-corcles](https://demo.pages.djmil.dev/egui-circles/index.html) project, incorrect MIME is returned for *.js files failing the whole Pages flow **Expected:** > _get_ https://demo.pages.djmil.dev/egui-circles/egui-circles-4f8030f072449e22.js Content-Type: application/javascript **Actual:** > _get_ https://demo.pages.djmil.dev/egui-circles/egui-circles-4f8030f072449e22.js Content-Type: text/plain; charset=utf-8
Author
Owner

Caddyserver github issue:

Go pulls mime type mappings from the operating system (mailcap file locations), so if it's not correctly set on your system, then it won't serve the right content type

Check file mime type:

file --mime-type -b sw.js
> text/plain

Possible sollutions

  1. Add custom mime type (ubuntu)
  2. Modify Caddyfile with header /*.js Content-Type text/javascript
  3. Caddy Apline mailcap docker discussion
Caddyserver github [issue](https://github.com/caddyserver/caddy/issues/4734): > Go pulls mime type mappings from the operating system (mailcap file locations), so if it's not correctly set on your system, then it won't serve the right content type Check file mime type: ```bash file --mime-type -b sw.js > text/plain ``` # Possible sollutions 1. Add custom mime type ([ubuntu](https://help.ubuntu.com/community/AddingMimeTypes)) 2. Modify `Caddyfile` with `header /*.js Content-Type text/javascript` 2. Caddy Apline mailcap docker [discussion](https://caddy.community/t/v2-how-to-handle-mime-information/7559/5)
djmil self-assigned this 2024-08-08 22:27:05 +02:00
Author
Owner

Updating Alpine's MIME type internals seems to be hard and not easily automated (for the docker images). Thus it looks that i have to focus on editing Caddyfile to enable remapping of Content type for *.js files.

Updating Alpine's MIME type internals seems to be hard and not easily automated (for the docker images). Thus it looks that i have to focus on editing `Caddyfile` to enable remapping of Content type for *.js files.
Author
Owner

Caddy 2 does not sniff MIME by default, either, for security reasons; if a Content-Type is missing you may need to set the header yourself using the header directive. (c)

Caddyfile structure

Caddyfile Blocks

When there is only one site block, the curly braces (and indentation) are optional (c)

Going to try to modify the default Caddyfile with

:3003 {       # site
	gitea {   # plugin
		token  {$GITEA_ACCESS_TOKEN} # Settings > Applications > Generate Token
		server {$GITEA_HOST}   # https://yourgitea.yourdomain.com
		domain {$PAGES_DOMAIN} #             pages.yourdomain.com
	}
	
	@js {        # matcher definition
		path *.js
	}

	header @js { # directive
		Content-Type text/javascript
	}
}
> Caddy 2 does not sniff MIME by default, either, for security reasons; if a Content-Type is missing you may need to **set the header yourself using the header directive**. [(c)](https://caddyserver.com/docs/v2-upgrade#primary-changes) `Caddyfile` [structure](https://caddyserver.com/docs/caddyfile/concepts#structure) ### Caddyfile Blocks > When there is only one site block, the curly braces (and indentation) are optional [(c)](https://caddyserver.com/docs/caddyfile/concepts#blocks) Going to try to modify the default `Caddyfile` with ```Caddyfile :3003 { # site gitea { # plugin token {$GITEA_ACCESS_TOKEN} # Settings > Applications > Generate Token server {$GITEA_HOST} # https://yourgitea.yourdomain.com domain {$PAGES_DOMAIN} # pages.yourdomain.com } @js { # matcher definition path *.js } header @js { # directive Content-Type text/javascript } } ```
djmil added the
bug
label 2024-08-20 22:06:03 +02:00
djmil added this to the 0.1.0 milestone 2024-08-20 22:12:17 +02:00
djmil closed this issue 2024-08-22 21:06:27 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: djmil/gitea-pages#3
No description provided.