How to set mime-type for SimpleHTTPServer?

38 views
Skip to first unread message

キャロウ マーク

unread,
Jul 19, 2019, 8:06:45 PM7/19/19
to emscripten-discuss
I am attempting to test my app using python -m SimpleHTTPServer. I see the following in the browser console:

wasm streaming compile failed: TypeError: Response has unsupported MIME type

How can I get SimpleHTTPServer to serve the wasm file with the correct mime type?

Regards

    -Mark
signature.asc

Joshua Moore

unread,
Jul 19, 2019, 8:23:16 PM7/19/19
to emscripte...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/8BBAD5A0-FE41-41A9-831F-1D6665D92C65%40callow.im.

キャロウ マーク

unread,
Jul 19, 2019, 8:29:24 PM7/19/19
to emscripten-discuss


On Jul 19, 2019, at 17:23, Joshua Moore <joshua...@leudla.net> wrote:


Thanks but how do I add that to my Python?

Regards

    -Mark

signature.asc

Joshua Moore

unread,
Jul 19, 2019, 8:34:40 PM7/19/19
to emscripte...@googlegroups.com
It looks like you are using python 2, which will be deprecated in 2020. If you have the choice of installing python 3, the code above should work. Put the code in a script called something like "server.py", then run it via python3 server.py. 

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

Joshua Moore

unread,
Jul 19, 2019, 8:36:43 PM7/19/19
to emscripte...@googlegroups.com
If you do not have the option of installing python3, try this code: 

#!/usr/bin/env python
import BaseHTTPServer, SimpleHTTPServer
 
port=8000
print "Running on port %d" % port
 
SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map['.wasm'] =    'application/wasm' 
httpd = BaseHTTPServer.HTTPServer(('localhost', port),
    SimpleHTTPServer.SimpleHTTPRequestHandler)
 
print "Mapping \".wasm\" to \"%s\"" %
    SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map['.wasm']
httpd.serve_forever()

(Source: https://curiousprog.com/2018/10/08/serving-webassembly-files-with-a-development-web-server/)

キャロウ マーク

unread,
Jul 19, 2019, 8:39:55 PM7/19/19
to emscripten-discuss
Thanks. I have Python 3 as well, I’ll use that.
signature.asc

キャロウ マーク

unread,
Jul 19, 2019, 8:47:31 PM7/19/19
to emscripten-discuss


> On Jul 19, 2019, at 17:39, キャロウ マーク <git...@callow.im> wrote:
>
> Thanks. I have Python 3 as well, I’ll use that.

I’m still getting the message even when running the script to start the server.



signature.asc

Floh

unread,
Jul 20, 2019, 9:39:36 AM7/20/19
to emscripten-discuss
I started using the node.js http-server module instead of the python server.

It has the proper wasm mime type, and also supports other HTTP features the python http server doesn't support (for instance range-requests):

> npm install -g http-server
> http-server
Starting up http-server, serving ./
Available on:
Hit CTRL-C to stop the server

Cheer,
-Floh.

キャロウ マーク

unread,
Jul 22, 2019, 1:47:52 PM7/22/19
to emscripten-discuss


> On Jul 20, 2019, at 6:39, Floh <flo...@gmail.com> wrote:
>
> I started using the node.js http-server module instead of the python server.
>
> It has the proper wasm mime type, and also supports other HTTP features the python http server doesn't support (for instance range-requests):
>
> > npm install -g http-server
> > http-server
> Starting up http-server, serving ./
> Available on:
> http://127.0.0.1:8080
> http://192.168.44.44:8080
> Hit CTRL-C to stop the server
>

Thanks Floh. This is working a treat and I like being able to use range requests. The only small niggle is that the “>” prompt made me think these commands had to be issued from within node.js. But they are for the regular shell.

Regards

-Mark

signature.asc
Reply all
Reply to author
Forward
0 new messages