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

python3 -m http.server returns wrong MIME type for javascript files causing samples not to work #111

Closed
hfmanson opened this issue Jul 22, 2023 · 4 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior. effort: medium Task is a medium effort. p2 We want to address this but may have other higher priority items.

Comments

@hfmanson
Copy link

hfmanson commented Jul 22, 2023

in README.md it's suggested to run the samples with

python3 -m http.server

However this server returns the text/html MIME type for .js and .css files. Therefore, on Chrome the audioworklet sample does not work.

I now use this Python script, providing the correct MIME type for javascript and css files.

try:
    from http import server # Python 3
except ImportError:
    import SimpleHTTPServer as server # Python 2

if __name__ == '__main__':
    server.SimpleHTTPRequestHandler.extensions_map['.js'] = 'application/javascript'
    server.SimpleHTTPRequestHandler.extensions_map['.css'] = 'text/css'
    server.test(port=8114, HandlerClass=server.SimpleHTTPRequestHandler, protocol="HTTP/1.1")
@github-actions
Copy link

It looks like this is your first issue. Welcome! 👋
One of the project maintainers will be with you as soon as possible. We
appreciate your patience. To safeguard the health of the project, please
take a moment to read our code of conduct.

@bsmth bsmth self-assigned this Jul 25, 2023
@github-actions github-actions bot added the idle Issues and pull requests with no activity for three months. label Aug 25, 2023
@caugner caugner added effort: medium Task is a medium effort. bug Indicates an unexpected problem or unintended behavior. p2 We want to address this but may have other higher priority items. and removed idle Issues and pull requests with no activity for three months. labels Oct 16, 2023
@bsmth
Copy link
Member

bsmth commented Dec 12, 2023

Hi @hfmanson - thanks a lot for reporting this one.

I had a look into this, and I can't reproduce this on Firefox or Chrome. You can also check using curl to see the returned content-type:

# Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
cd path/to/webaudio-examples/audioworklet
python3 -m http.server
# ...
curl -v localhost:8000/script.js
*   Trying 127.0.0.1:8000...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET /script.js HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/8.1.2
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: SimpleHTTP/0.6 Python/3.11.5
< Date: Tue, 12 Dec 2023 15:41:52 GMT
< Content-type: application/javascript
< Content-Length: 2611
< Last-Modified: Thu, 29 Jun 2023 15:18:38 GMT

It could be that this has been fixed in the meantime, but I've tested using Python 3.11.5.

I'm going to close for the moment, but if you have some other info, let me know here! Thanks a lot!

@bsmth bsmth closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2023
@hfmanson
Copy link
Author

Indeed, it's a python problem:
SimpleHTTP/0.6 Python/3.10.12 on Linux returns text/javascript
SimpleHTTP/0.6 Python/3.10.9 on Windows returns text/plain
as MIME type on a .js files

I agree on closing the issue, maybe mention python version should be at least 3.10.12

@bsmth
Copy link
Member

bsmth commented Dec 15, 2023

Thanks for getting back, I'm glad we got to the bottom of it.

mention python version should be at least 3.10.12

That's a good idea, we can add a note in the docs. 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior. effort: medium Task is a medium effort. p2 We want to address this but may have other higher priority items.
Projects
None yet
Development

No branches or pull requests

3 participants