Skip to content

SEO Compatible Rendering #186

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

Merged
merged 20 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use_origin and use_connection support
  • Loading branch information
Archmonger committed Sep 15, 2023
commit d1fe1c403b4f5eecea5a659fcda689300ba4495a
26 changes: 18 additions & 8 deletions src/reactpy_django/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,24 @@ def use_origin() -> str | None:
this will be None."""
scope = _use_scope()
try:
return next(
(
header[1].decode("utf-8")
for header in scope["headers"]
if header[0] == b"origin"
),
None,
)
if scope["type"] == "websocket":
return next(
(
header[1].decode("utf-8")
for header in scope["headers"]
if header[0] == b"origin"
),
None,
)
if scope["type"] == "http":
host = next(
(
header[1].decode("utf-8")
for header in scope["headers"]
if header[0] == b"host"
)
)
return f"{scope['scheme']}://{host}" if host else None
except Exception:
return None

Expand Down
3 changes: 2 additions & 1 deletion src/reactpy_django/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from django.db.models.base import Model
from django.db.models.query import QuerySet
from django.http import HttpRequest
from django.views.generic import View
from reactpy.types import Connection as _Connection
from typing_extensions import ParamSpec
Expand Down Expand Up @@ -50,7 +51,7 @@ class ComponentWebsocket:
dotted_path: str


Connection = _Connection[ComponentWebsocket]
Connection = _Connection[ComponentWebsocket | HttpRequest]


@dataclass
Expand Down