Merge pull request #126 from space-nuko/server-args

Add arguments to serve.py
This commit is contained in:
space-nuko
2023-07-07 09:49:27 -05:00
committed by GitHub

View File

@@ -2,15 +2,19 @@
import http.server import http.server
import socketserver import socketserver
import argparse
PORT = 8000 parser = argparse.ArgumentParser()
parser.add_argument("-l", "--listen", type=str, default="localhost", help="Listen address for ComfyBox server")
parser.add_argument("-p", "--port", type=int, default=8000, help="Port for ComfyBox server")
args = parser.parse_args()
message = f"""Starting ComfyBox. message = f"""Starting ComfyBox.
Be sure you've started ComfyUI already using this command: Be sure you've started ComfyUI already using this command:
python main.py --enable-cors-header python main.py --enable-cors-header
Serving at http://localhost:{PORT}... Serving at http://{args.listen}:{args.port}...
""" """
# python -m http.server will sometimes send incorrect MIME types. # python -m http.server will sometimes send incorrect MIME types.
@@ -19,33 +23,34 @@ Serving at http://localhost:{PORT}...
# Hopefully this will cover everything. # Hopefully this will cover everything.
class HttpRequestHandler(http.server.SimpleHTTPRequestHandler): class HttpRequestHandler(http.server.SimpleHTTPRequestHandler):
extensions_map = { extensions_map = {
'': 'application/octet-stream', "": "application/octet-stream",
'.manifest': 'text/cache-manifest', ".manifest": "text/cache-manifest",
'.html': 'text/html', ".html": "text/html",
'.png': 'image/png', ".png": "image/png",
'.jpg': 'image/jpg', ".jpg": "image/jpg",
'.jpeg': 'image/jpeg', ".jpeg": "image/jpeg",
'.gif': 'image/gif', ".gif": "image/gif",
'.svg': 'image/svg+xml', ".svg": "image/svg+xml",
'.css': 'text/css', ".css": "text/css",
'.js': 'application/x-javascript', ".js": "application/x-javascript",
'.mjs': 'application/x-javascript', ".mjs": "application/x-javascript",
'.cjs': 'application/x-javascript', ".cjs": "application/x-javascript",
'.wasm': 'application/wasm', ".wasm": "application/wasm",
'.json': 'application/json', ".json": "application/json",
'.xml': 'application/xml', ".xml": "application/xml",
'.xml': 'application/xml', ".xml": "application/xml",
'.pdf': 'application/pdf', ".pdf": "application/pdf",
'.webp': 'image/webp', ".webp": "image/webp",
'.avif': 'image/avif', ".avif": "image/avif",
'.heic': 'image/heic', ".heic": "image/heic",
'.heif': 'image/heif', ".heif": "image/heif",
'.mp3': 'audio/mpeg', ".mp3": "audio/mpeg",
'.mp4': 'video/mp4', ".mp4": "video/mp4",
'.m4v': 'video/mp4' ".m4v": "video/mp4",
} }
httpd = socketserver.TCPServer(("localhost", PORT), HttpRequestHandler)
httpd = socketserver.TCPServer((args.listen, args.port), HttpRequestHandler)
try: try:
print(message) print(message)