mount-point for clean URLs #550
Replies: 2 comments
-
|
Beta Was this translation helpful? Give feedback.
-
FPM AppsDiscussion: https://github.com/ftd-lang/fpm/discussions/599 |
Beta Was this translation helpful? Give feedback.
-
Status: Done
Follow: #526
PR: #587
With endpoint support, if we have a dependency:
Then todo app gets deployed on:
abrark.com/-/fifthtry.github.io/todos/
. This is also the case if you are using any package as static package, say you wanted a packagefifthtry.github.io/icons/
and it has exposed an iconclose.png
, you have to use the URL:abrark.com/-/fifthtry.github.io/icons/close.png
.This way of constructing URLs give us name spacing, so we can add any number of packages and apps without worrying about conflict. But these URLs are ugly, especially if we want to share the URL with others.
mount-point
To solve this we support
mount-point
.mount-point
can be added to any dependency. When constructing URL the normal rule of<package-name>/-/<dependency-package>
would not be used if mount-point is used, instead we will use the rule<package-name><dependency-package-mount-point>
instead.Both URLs will be served by fpm serve, but if
mount-point
is defined, when fpm is constructing a URL it will use themount-point
url.Multiple Dependencies
We can install any number of dependencies, each with their own
end-point
, andmount-point
settings.mount-point
must be unique for each of them, if not we will give an error.Proper URL Handling in End-Point
When a request to
abrark.com/-/fifthtry.github.io/todos/
orabrark.com/todos/
is made with this setup, the request will proxy-passed to the endpoint (https://abrark-todos.herokuapps.com
).Normalised Path
The path parameter should be normalised. Since both URLs are valid, which URL would django use in
urls.py
? One option is we strip out both/todos/
and/-/fifthtry.github.io/todos/
, and pass just the part that comes after to django as PATH parameter.So if request came to
/todos/1/
, django will get/1/
.Generating URLs
Django needs to generate URLs as well. To generate URLs django must use the value of header named
X-FPM-MOUNT-POINT
. So instead of including/1/
in JSON/HTML, django will use:request.headers["X-FPM-MOUNT-POINT"] + "/1/"
.Endpoint should block content-type HTML
So django etc an only be used for providing APIs and not web pages.
Beta Was this translation helpful? Give feedback.
All reactions