Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack to get emujs working in dev mode #1139

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions backend/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def str_to_bool(value: str) -> bool:


# GUNICORN
DEV_PORT: Final = int(os.environ.get("VITE_BACKEND_DEV_PORT", "5000"))
DEV_HOST: Final = "127.0.0.1"
DEV_MODE: Final = str_to_bool(os.environ.get("DEV_MODE", "false"))
DEV_HOST: Final = os.environ.get("DEV_HOST", "127.0.0.1")
DEV_PORT: Final = int(os.environ.get("DEV_PORT", "5000"))
GUNICORN_WORKERS: Final = int(os.environ.get("GUNICORN_WORKERS", 2))

# PATHS
Expand Down
15 changes: 15 additions & 0 deletions backend/endpoints/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from anyio import Path, open_file
from config import (
DEV_MODE,
DISABLE_DOWNLOAD_ENDPOINT_AUTH,
LIBRARY_BASE_PATH,
RESOURCES_BASE_PATH,
Expand All @@ -23,6 +24,7 @@
from handler.metadata import meta_igdb_handler, meta_moby_handler
from logger.logger import log
from starlette.requests import ClientDisconnect
from starlette.responses import FileResponse
from streaming_form_data import StreamingFormDataParser
from streaming_form_data.targets import FileTarget, NullTarget
from utils.filesystem import sanitize_filename
Expand Down Expand Up @@ -178,9 +180,22 @@ async def head_rom_content(
if not rom:
raise RomNotFoundInDatabaseException(id)

rom_path = f"{LIBRARY_BASE_PATH}/{rom.full_path}"
files_to_check = files or [r["filename"] for r in rom.files]

if not rom.multi:
# Serve the file directly in development mode for emulatorjs
if DEV_MODE:
return FileResponse(
path=rom_path,
filename=rom.file_name,
headers={
"Content-Disposition": f'attachment; filename="{quote(rom.file_name)}"',
"Content-Type": "application/octet-stream",
"Content-Length": str(rom.file_size_bytes),
},
)

return Response(
media_type="application/octet-stream",
headers={
Expand Down
2 changes: 1 addition & 1 deletion env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ROMM_BASE_PATH=/path/to/romm_mock
VITE_BACKEND_DEV_PORT=5000
DEV_MODE=true

# Gunicorn (optional)
GUNICORN_WORKERS=4 # (2 × CPU cores) + 1
Expand Down
2 changes: 1 addition & 1 deletion frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { defineConfig, loadEnv } from "vite";
export default defineConfig(({ mode }) => {
// Load ENV variables from the parent directory and the current directory.
const env = { ...loadEnv(mode, "../"), ...loadEnv(mode, "./") };
const backendPort = env.VITE_BACKEND_DEV_PORT ?? "5000";
const backendPort = env.DEV_PORT ?? "5000";

return {
build: {
Expand Down
Loading