Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option "mimeOverride" so you can override MIME/Content-Type headers #103

Closed

Conversation

eirslett
Copy link

The use-case for this is bundlers like Vite, that serve compiled
TypeScript with a .ts file extension. The MIME standard has assigned
content video/mp2t to the .ts extension, but in the case of bundlers,
they would need to serve these files with "Content-Type: application/javascript".

Here is the specific use case: vitejs/vite#2642

The use-case for this is bundlers like Vite, that serve compiled
TypeScript with a .ts file extension. The MIME standard has assigned
content video/mp2t to the .ts extension, but in the case of bundlers,
they would need to serve these files with "Content-Type: application/javascript".
@lukeed
Copy link
Owner

lukeed commented Mar 29, 2021

Hi, thank you, but this should be done in setHeaders as it's given all the necessary information (and window of opportunity) to make that override.

sirv('dir', {
  // ...
  setHeaders(res, pathname) {
    if (/\.[tj]sx?$/.test(pathname)) {
      res.setHeader('Content-Type', 'text/javascript');
    }
  }
})

@lukeed lukeed closed this Mar 29, 2021
eirslett added a commit to eirslett/vite that referenced this pull request Mar 29, 2021
This fixes vitejs#2642.
Thanks a lot to @lukeed, maintainer of Sirv, for the suggestion!
lukeed/sirv#103 (comment)
@eirslett eirslett deleted the feature/override-content-types branch March 29, 2021 20:47
eirslett added a commit to eirslett/vite that referenced this pull request Mar 29, 2021
This fixes vitejs#2642.
Thanks a lot to @lukeed, maintainer of Sirv, for the suggestion!
lukeed/sirv#103 (comment)
eirslett added a commit to eirslett/vite that referenced this pull request Mar 29, 2021
This fixes vitejs#2642.
Thanks a lot to @lukeed, maintainer of Sirv, for the suggestion!
lukeed/sirv#103 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants