Yes, we should make this fact clearer in the documentation.
As for testing content locally, I use this server script, that just serves the folder given to it as an argument:
cors_server.py
#!/usr/bin/env python3
# encoding: utf-8
"""Use instead of `python3 -m http.server` when you need CORS"""
import sys, socket
from http.server import HTTPServer, SimpleHTTPRequestHandler
hostname = socket.gethostname()
local_ip = '192.168.0.210'# socket.gethostbyname(hostname)
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
SimpleHTTPRequestHandler.end_headers(self)
port = 8000
if len(sys.argv) > 1:
port = int(sys.argv[1],10)
print("Listening on", local_ip, port)
httpd = HTTPServer((local_ip, port), CORSRequestHandler)
httpd.serve_forever()
And I also have a helper script to unpack and serve the latest defold.resourcepack_*.zip
. It really helps testing a lot faster. It invokes the cors_server-py
script. Feel free to make any changes necessary to make it work for your use case:
liveupdate.sh
#!/usr/bin/env bash
set -e
SCRIPTDIR=$(pwd)
DIR=./liveupdate
if [ -d "$DIR" ]; then
rm -rf $DIR
echo Removed $DIR
fi
ZIP=$(ls -t defold.resourcepack*.zip | head -1)
if [ "$ZIP" == "" ]; then
echo "No resourcepack found!"
exit 1
fi
echo "Found $ZIP"
ls -la $ZIP
unzip -q $ZIP -d $DIR
cp -v $ZIP $DIR/defold.resourcepack.zip
cp /Users/mawe/work/projects/users/denis.smirnov/issue-5499/liveupdate_version $DIR
(cd $DIR && python3 $SCRIPTDIR/cors_server.py)
EDIT: You can ofc use python -m http.server
but then the 304 messages won’t be handled properly and it will always download the data.