mdn / webaudio-examples

Code examples that accompany the MDN Web Docs pages relating to Web Audio.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API
Creative Commons Zero v1.0 Universal
1.28k stars 433 forks source link

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

Closed hfmanson closed 11 months ago

hfmanson commented 1 year ago

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[bot] commented 1 year ago

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 commented 11 months ago

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!

hfmanson commented 11 months ago

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 commented 11 months ago

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. 👍🏻