Merge pull request #36 from space-nuko/custom-serve-script
Serve script that sends correct MIME types
This commit is contained in:
11
bin/run.bat
11
bin/run.bat
@@ -1,11 +1,4 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
echo Starting ComfyBox.
|
cd /D "%~dp0"
|
||||||
echo Be sure you've started ComfyUI already using this command:
|
python serve.py
|
||||||
echo[
|
|
||||||
echo python main.py --enable-cors-header
|
|
||||||
echo[
|
|
||||||
echo Serving at http://localhost:8000
|
|
||||||
echo[
|
|
||||||
|
|
||||||
python -m http.server 8000
|
|
||||||
|
|||||||
11
bin/run.sh
11
bin/run.sh
@@ -1,11 +1,4 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
echo "Starting ComfyBox."
|
cd "${0%/*}"
|
||||||
echo "Be sure you've started ComfyUI already using this command:"
|
python serve.py
|
||||||
echo ""
|
|
||||||
echo " python main.py --enable-cors-header"
|
|
||||||
echo ""
|
|
||||||
echo "Serving at http://localhost:8000"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
python -m http.server 8000
|
|
||||||
|
|||||||
54
bin/serve.py
Normal file
54
bin/serve.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import http.server
|
||||||
|
import socketserver
|
||||||
|
|
||||||
|
PORT = 8000
|
||||||
|
|
||||||
|
message = f"""Starting ComfyBox.
|
||||||
|
Be sure you've started ComfyUI already using this command:
|
||||||
|
|
||||||
|
python main.py --enable-cors-header
|
||||||
|
|
||||||
|
Serving at http://localhost:{PORT}...
|
||||||
|
"""
|
||||||
|
|
||||||
|
# python -m http.server will sometimes send incorrect MIME types.
|
||||||
|
# But most people have a system python already installed so this method is most convenient.
|
||||||
|
# So here is a list of MIME types for the server to send back per file extension.
|
||||||
|
# Hopefully this will cover everything.
|
||||||
|
class HttpRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
|
extensions_map = {
|
||||||
|
'': 'application/octet-stream',
|
||||||
|
'.manifest': 'text/cache-manifest',
|
||||||
|
'.html': 'text/html',
|
||||||
|
'.png': 'image/png',
|
||||||
|
'.jpg': 'image/jpg',
|
||||||
|
'.jpeg': 'image/jpeg',
|
||||||
|
'.gif': 'image/gif',
|
||||||
|
'.svg': 'image/svg+xml',
|
||||||
|
'.css': 'text/css',
|
||||||
|
'.js': 'application/x-javascript',
|
||||||
|
'.mjs': 'application/x-javascript',
|
||||||
|
'.cjs': 'application/x-javascript',
|
||||||
|
'.wasm': 'application/wasm',
|
||||||
|
'.json': 'application/json',
|
||||||
|
'.xml': 'application/xml',
|
||||||
|
'.xml': 'application/xml',
|
||||||
|
'.pdf': 'application/pdf',
|
||||||
|
'.webp': 'image/webp',
|
||||||
|
'.avif': 'image/avif',
|
||||||
|
'.heic': 'image/heic',
|
||||||
|
'.heif': 'image/heif',
|
||||||
|
'.mp3': 'audio/mpeg',
|
||||||
|
'.mp4': 'video/mp4',
|
||||||
|
'.m4v': 'video/mp4'
|
||||||
|
}
|
||||||
|
|
||||||
|
httpd = socketserver.TCPServer(("localhost", PORT), HttpRequestHandler)
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(message)
|
||||||
|
httpd.serve_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
@@ -23,6 +23,10 @@ export default defineConfig({
|
|||||||
svelte(),
|
svelte(),
|
||||||
viteStaticCopy({
|
viteStaticCopy({
|
||||||
targets: [
|
targets: [
|
||||||
|
{
|
||||||
|
src: 'bin/serve.py',
|
||||||
|
dest: './'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
src: 'bin/run.sh',
|
src: 'bin/run.sh',
|
||||||
dest: './'
|
dest: './'
|
||||||
|
|||||||
Reference in New Issue
Block a user