-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to modify component's host URLs (#172)
### Added - **Distributed Computing:** ReactPy components can now optionally be rendered by a completely separate server! - `REACTPY_DEFAULT_HOSTS` setting can round-robin a list of ReactPy rendering hosts. - `host` argument has been added to the `component` template tag to force components to render on a specific host. - `reactpy_django.utils.register_component` function to manually register root components. - Useful if you have dedicated ReactPy rendering application(s) that do not use HTML templates. ### Changed - ReactPy will now provide a warning if your HTTP URLs are not on the same prefix as your websockets. - Cleaner logging output for detected ReactPy root components. ### Deprecated - `reactpy_django.REACTPY_WEBSOCKET_PATH` is deprecated. The similar replacement is `REACTPY_WEBSOCKET_ROUTE`. - `settings.py:REACTPY_WEBSOCKET_URL` is deprecated. The similar replacement is `REACTPY_URL_PREFIX`. ### Removed - Warning W007 (`REACTPY_WEBSOCKET_URL doesn't end with a slash`) has been removed. ReactPy now automatically handles slashes. - Warning W008 (`REACTPY_WEBSOCKET_URL doesn't start with an alphanumeric character`) has been removed. ReactPy now automatically handles this scenario. - Error E009 (`channels is not in settings.py:INSTALLED_APPS`) has been removed. Newer versions of `channels` do not require installation via `INSTALLED_APPS` to receive an ASGI webserver.
- Loading branch information
1 parent
88acbaf
commit 41641aa
Showing
31 changed files
with
584 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,8 +89,8 @@ celerybeat-schedule.* | |
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
.env*/ | ||
.venv*/ | ||
env/ | ||
venv/ | ||
ENV/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.apps import AppConfig | ||
from reactpy_django.utils import register_component | ||
|
||
|
||
class ExampleConfig(AppConfig): | ||
def ready(self): | ||
# Add components to the ReactPy component registry when Django is ready | ||
register_component("example_project.my_app.components.hello_world") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,59 @@ | ||
import { mountLayoutWithWebSocket } from "@reactpy/client"; | ||
|
||
// Set up a websocket at the base endpoint | ||
const LOCATION = window.location; | ||
let HTTP_PROTOCOL = window.location.protocol; | ||
let WS_PROTOCOL = ""; | ||
if (LOCATION.protocol == "https:") { | ||
WS_PROTOCOL = "wss://"; | ||
if (HTTP_PROTOCOL == "https:") { | ||
WS_PROTOCOL = "wss:"; | ||
} else { | ||
WS_PROTOCOL = "ws://"; | ||
WS_PROTOCOL = "ws:"; | ||
} | ||
const WS_ENDPOINT_URL = WS_PROTOCOL + LOCATION.host + "/"; | ||
|
||
export function mountViewToElement( | ||
mountElement, | ||
reactpyWebsocketUrl, | ||
reactpyWebModulesUrl, | ||
maxReconnectTimeout, | ||
componentPath | ||
reactpyHost, | ||
reactpyUrlPrefix, | ||
reactpyReconnectMax, | ||
reactpyComponentPath, | ||
reactpyResolvedWebModulesPath | ||
) { | ||
const WS_URL = WS_ENDPOINT_URL + reactpyWebsocketUrl + componentPath; | ||
const WEB_MODULE_URL = LOCATION.origin + "/" + reactpyWebModulesUrl; | ||
// Determine the Websocket route | ||
let wsOrigin; | ||
if (reactpyHost) { | ||
wsOrigin = `${WS_PROTOCOL}//${reactpyHost}`; | ||
} else { | ||
wsOrigin = `${WS_PROTOCOL}//${window.location.host}`; | ||
} | ||
const websocketUrl = `${wsOrigin}/${reactpyUrlPrefix}/${reactpyComponentPath}`; | ||
|
||
// Determine the HTTP route | ||
let httpOrigin; | ||
let webModulesPath; | ||
if (reactpyHost) { | ||
httpOrigin = `${HTTP_PROTOCOL}//${reactpyHost}`; | ||
webModulesPath = `${reactpyUrlPrefix}/web_module`; | ||
} else { | ||
httpOrigin = `${HTTP_PROTOCOL}//${window.location.host}`; | ||
if (reactpyResolvedWebModulesPath) { | ||
webModulesPath = reactpyResolvedWebModulesPath; | ||
} else { | ||
webModulesPath = `${reactpyUrlPrefix}/web_module`; | ||
} | ||
} | ||
const webModuleUrl = `${httpOrigin}/${webModulesPath}`; | ||
|
||
// Function that loads the JavaScript web module, if needed | ||
const loadImportSource = (source, sourceType) => { | ||
return import( | ||
sourceType == "NAME" ? `${WEB_MODULE_URL}${source}` : source | ||
sourceType == "NAME" ? `${webModuleUrl}/${source}` : source | ||
); | ||
}; | ||
|
||
// Start rendering the component | ||
mountLayoutWithWebSocket( | ||
mountElement, | ||
WS_URL, | ||
websocketUrl, | ||
loadImportSource, | ||
maxReconnectTimeout | ||
reactpyReconnectMax | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.