1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Created Design: Custom Node admin route handling (markdown)

Nick O'Leary 2018-05-14 13:18:35 +01:00
parent f8fa500c98
commit 240444abda

@ -0,0 +1,31 @@
Nodes are able to add their own custom routes to the `RED.httpAdmin` express app. This allows them to:
- provide their own admin routes - such as the Serial node's ability to query active ports on the host
- serve up additional content - such as Debug loading its shared .js library and node-red-node-geofence loading the leaflet.js library and associated resources.
Within the editor, as long as their reference those routes with a relative url, they will work regardless of what `httpAdminRoot` is set to.
This poses some problems for the split of the editor and runtime.
One of the goals of the split is to be able to serve the editor from a static file server (eg AWS S3) and point it at a server hosting the admin api. At this point, any relative urls a custom node uses will break - as they will be relative to the S3 url, not the admin api url.
There are a number of ways a user may access these custom routes - each needs a slightly different solution.
| Type of route | Resolution |
| ------------- | ------------- |
| `$.ajax` call | We already use `$.ajaxSetup()` to attach access tokens to relative urls. That can be updated to rewrite urls |
| **Adding scripts to the page** | |
| `$.getScript` | Also covered by `$.ajaxSetup()` fix |
| `<script>` at the top level of the HTML | When we load a node's HTML content, we can parse it, look for any script tag with a relative src url and rewrite it. Prototyping this shows it then causes issues with scripts not being loaded in the same order. Will need some extra logic to find and load all external scripts first before adding node HTML content. |
| Any other mechanism | If we cannot intercept the src url, we cannot fix. This method must be deprecated. |
| **Adding external stylesheets to the page** | |
| `<link>` at the top level of the HTML | As with `<script>` - we can parse and identify such links before adding to the DOM |
| `<link>` inside edit template `<script>` | As with `<script>`, but this happens each time the edit dialog is opened for a node. |
| **Adding images to the page** | |
| `<img>` in edit template | As with `<script>`, but this happens each time the edit dialog is opened for a node. |
| Dynamically added via code | We cannot intercept these - no good solution to keep things working as it |
So we can cover a number of the cases via code inspection and url rewriting - but not all. I don't know how common it is for nodes to add custom images - but its possible to do so.