Files
Ryth Azhur 1b5dca5ab3 SSR: file-path rendering, no component registry
The worker receives a file path in the JSON message, dynamically
imports it, renders it. No registerComponent API, no app entry file,
no export maps. Django's template backend resolves the template name
to an absolute path against DIRS, same as every other template engine.

  render(request, 'components/Hello.tsx', {'name': 'World'})

Verified working: curl http://localhost:8000/hello/ returns
  <div id="mizan-root"><div>Hello, World!</div></div>

Changes:
- worker.tsx: receives file path, dynamic import with cache
- bridge.py: sends file path instead of component name
- backend.py: resolves template name against DIRS to absolute path
- Fix bridge.py:147 bug (referenced deleted 'component' variable)
- Example app: Hello.tsx component, /hello/ view, template config

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 03:33:01 -04:00

90 lines
2.1 KiB
Python

"""
Django settings for the integration test backend.
Provides:
- HTTP server functions (echo, add)
- WebSocket channels (chat, notifications, presence)
- JWT authentication
- Form integration (login, signup, add_email)
"""
import os
SECRET_KEY = "integration-test-secret-key-not-for-production"
DEBUG = True
ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"mizan",
"testapp",
]
AUTH_USER_MODEL = "testapp.EmailUser"
MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
]
ROOT_URLCONF = "testapp.urls"
TEMPLATES = [
{
"BACKEND": "mizan.ssr.MizanTemplates",
"DIRS": [os.path.join(os.path.dirname(__file__), "..", "..", "frontend")],
"OPTIONS": {
"worker": os.path.join(
os.path.dirname(__file__), "..", "..", "..", "..",
"packages", "mizan-ssr", "src", "worker.tsx",
),
},
},
]
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(os.path.dirname(__file__), "..", "db.sqlite3"),
}
}
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
ASGI_APPLICATION = "testapp.asgi.application"
# JWT
JWT_PRIVATE_KEY = "integration-test-jwt-secret-key"
JWT_ALGORITHM = "HS256"
# Channel layers — Redis when available, in-memory fallback for local dev
REDIS_URL = os.environ.get("REDIS_URL", "")
if REDIS_URL:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {"hosts": [REDIS_URL]},
},
}
else:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer",
},
}
# Session
SESSION_ENGINE = "django.contrib.sessions.backends.db"
# CORS — allow React dev server
CSRF_TRUSTED_ORIGINS = [
"http://localhost:3000",
"http://localhost:5173",
"http://localhost:5174",
]