Skip to content

Commit

Permalink
#2196 document how to configure the MIME type of the server
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanrauh committed Apr 20, 2024
1 parent 139e56a commit f97668f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions projects/ngx-extended-pdf-viewer/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,53 @@ There's also a layout glitch that seems to be intentional: you may need to set t

If you run into problems using `<ngx-extended-pdf-viewer>`, please open an issue on the [project bug tracker](https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues).

## "Failed to load module script: Expected a JavaScript module script but the server responds with a MIME type of "text/plain"

Update your server configuration. Many servers don't recognize `*.mjs` files as JavaScript. To fix this, you have to configure the server so it sends the file with the proper MIME type (`text/javascript`). You also have to configure the new i18n files. They've got the file ending `.ftl` and need the MIME type `text/plain`.

For example, IIS requires this configuration:

```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>

<system.webServer>
<staticContent>
<mimeMap fileExtension=".mjs" mimeType="text/javascript" />
<mimeMap fileExtension=".ftl" mimeType="text/plain" />
</staticContent>
</system.webServer>

</configuration>
```

nginx requires this configuration:

```json
location / {
...

location ~* \.mjs$ {
# target only *.mjs files
# now we can safely override types since we are only
# targeting a single file extension.
types {
text/javascript mjs;
}
}
}
```

AWS amplify requires this configuration in the `amplify.yaml` file:

```yaml
customHeaders:
- pattern: '*.mjs'
headers:
- key: 'Content-Type'
value: 'application/javascript'
```
## Compatibility to Bootstrap (and other CSS frameworks)
Bootstrap interferes with the printing algorithm of `pdf.js`. Guard it with a media query to avoid unwanted effects, such as scaling the print to 65%. For example, if you're using SCSS and Bootstrap 4, remove the import of Bootstrap.min.css from the Angular.json file. Instead, import it by including Bootstrap by adding this line to the global `styles.scss` file:
Expand Down

0 comments on commit f97668f

Please sign in to comment.