Replace local web server setup for web editor with a Python-based solution
This makes it easier to set up, as you always have Python installed when building Godot. On the other hand, you don't always have Node.js + npm installed (and you may not want to spend time running `npm install`). Co-authored-by: Fabio Alessandrelli <fabio.alessandrelli@gmail.com>
This commit is contained in:
parent
1371a97acf
commit
1be1b15a57
5 changed files with 57 additions and 1247 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -82,9 +82,9 @@ platform/android/java/*/libs/
|
|||
# iOS
|
||||
*.dSYM
|
||||
|
||||
# Javascript
|
||||
# Web platform
|
||||
*.bc
|
||||
platform/javascript/node_modules/
|
||||
platform/web/node_modules/
|
||||
|
||||
# Misc
|
||||
*.debug
|
||||
|
|
1221
platform/web/package-lock.json
generated
1221
platform/web/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -14,8 +14,7 @@
|
|||
"format:engine": "npm run lint:engine -- --fix",
|
||||
"format:libs": "npm run lint:libs -- --fix",
|
||||
"format:modules": "npm run lint:modules -- --fix",
|
||||
"format:tools": "npm run lint:tools -- --fix",
|
||||
"serve": "serve"
|
||||
"format:tools": "npm run lint:tools -- --fix"
|
||||
},
|
||||
"author": "Godot Engine contributors",
|
||||
"license": "MIT",
|
||||
|
@ -23,7 +22,6 @@
|
|||
"eslint": "^7.28.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1",
|
||||
"eslint-plugin-import": "^2.23.4",
|
||||
"jsdoc": "^3.6.7",
|
||||
"serve": "^13.0.2"
|
||||
"jsdoc": "^3.6.7"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"public": "../../bin",
|
||||
"headers": [{
|
||||
"source": "**/*",
|
||||
"headers": [
|
||||
{
|
||||
"key": "Cross-Origin-Embedder-Policy",
|
||||
"value": "require-corp"
|
||||
}, {
|
||||
"key": "Cross-Origin-Opener-Policy",
|
||||
"value": "same-origin"
|
||||
}, {
|
||||
"key": "Access-Control-Allow-Origin",
|
||||
"value": "*"
|
||||
}, {
|
||||
"key": "Cache-Control",
|
||||
"value": "no-store, max-age=0"
|
||||
}
|
||||
]
|
||||
}]
|
||||
}
|
52
platform/web/serve.py
Executable file
52
platform/web/serve.py
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from http.server import HTTPServer, SimpleHTTPRequestHandler, test # type: ignore
|
||||
from pathlib import Path
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import subprocess
|
||||
|
||||
|
||||
class CORSRequestHandler(SimpleHTTPRequestHandler):
|
||||
def end_headers(self):
|
||||
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
|
||||
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
|
||||
self.send_header("Access-Control-Allow-Origin", "*")
|
||||
super().end_headers()
|
||||
|
||||
|
||||
def shell_open(url):
|
||||
if sys.platform == "win32":
|
||||
os.startfile(url)
|
||||
else:
|
||||
opener = "open" if sys.platform == "darwin" else "xdg-open"
|
||||
subprocess.call([opener, url])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-p", "--port", help="port to listen on", default=8060, type=int)
|
||||
parser.add_argument(
|
||||
"-r", "--root", help="path to serve as root (relative to `platform/web/`)", default="../../bin", type=Path
|
||||
)
|
||||
browser_parser = parser.add_mutually_exclusive_group(required=False)
|
||||
browser_parser.add_argument(
|
||||
"-n", "--no-browser", help="don't open default web browser automatically", dest="browser", action="store_false"
|
||||
)
|
||||
parser.set_defaults(browser=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Change to the directory where the script is located,
|
||||
# so that the script can be run from any location.
|
||||
os.chdir(Path(__file__).resolve().parent)
|
||||
|
||||
if args.root:
|
||||
os.chdir(args.root)
|
||||
|
||||
if args.browser:
|
||||
# Open the served page in the user's default browser.
|
||||
print("Opening the served URL in the default browser (use `--no-browser` or `-n` to disable this).")
|
||||
shell_open(f"http://127.0.0.1:{args.port}")
|
||||
|
||||
test(CORSRequestHandler, HTTPServer, port=args.port)
|
Loading…
Reference in a new issue