Compare commits
2 Commits
f2a75a8c7a
...
d8a4b13c11
Author | SHA1 | Date |
---|---|---|
Ryan Rix | d8a4b13c11 | |
Ryan Rix | fee6eed87e |
|
@ -528,6 +528,7 @@ These are the route [[https://docs.djangoproject.com/en/3.2/topics/http/urls/][u
|
||||||
#+begin_src python :tangle arcology/urls.py
|
#+begin_src python :tangle arcology/urls.py
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, re_path, include
|
from django.urls import path, re_path, include
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from arcology import views
|
from arcology import views
|
||||||
|
|
||||||
|
@ -540,11 +541,14 @@ urlpatterns = [
|
||||||
path("feeds.json", views.feed_list, name="feed-list"),
|
path("feeds.json", views.feed_list, name="feed-list"),
|
||||||
path("", include("django_prometheus.urls")),
|
path("", include("django_prometheus.urls")),
|
||||||
path("", include("sitemap.urls")),
|
path("", include("sitemap.urls")),
|
||||||
path("api/v1/", include("localapi.urls")),
|
|
||||||
# ensure these ones are last because they're greedy!
|
# ensure these ones are last because they're greedy!
|
||||||
re_path("(?P<key>[0-9a-zA-Z/_\-]+\.xml)", views.feed, name="feed"),
|
re_path("(?P<key>[0-9a-zA-Z/_\-]+\.xml)", views.feed, name="feed"),
|
||||||
re_path("(?P<key>[0-9a-zA-Z/_\-]+)", views.org_page, name="org-page"),
|
re_path("(?P<key>[0-9a-zA-Z/_\-]+)", views.org_page, name="org-page"),
|
||||||
]
|
]
|
||||||
|
if settings.ARCOLOGY_ENVIRONMENT != "production":
|
||||||
|
urlpatterns = [
|
||||||
|
path("api/v1/", include("localapi.urls")),
|
||||||
|
] + urlpatterns
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
This is the topmatter for the views described below:
|
This is the topmatter for the views described below:
|
||||||
|
|
|
@ -48,7 +48,6 @@ INSTALLED_APPS = [
|
||||||
"generators", # [[id:arroyo/django/generators][The Arroyo Generators]]
|
"generators", # [[id:arroyo/django/generators][The Arroyo Generators]]
|
||||||
"syncthonk", # [[id:20231218T183551.765340][Arcology watchsync Command]]
|
"syncthonk", # [[id:20231218T183551.765340][Arcology watchsync Command]]
|
||||||
"sitemap", # [[id:20240226T132507.817450][The Arcology's Site Maps and Discovery Mechanisms]]
|
"sitemap", # [[id:20240226T132507.817450][The Arcology's Site Maps and Discovery Mechanisms]]
|
||||||
"localapi", # [[id:20240313T153901.656967][A Localhost API for the Arcology]]
|
|
||||||
|
|
||||||
"django_htmx",
|
"django_htmx",
|
||||||
"django_prometheus",
|
"django_prometheus",
|
||||||
|
@ -59,6 +58,8 @@ INSTALLED_APPS = [
|
||||||
"django.contrib.messages",
|
"django.contrib.messages",
|
||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
]
|
]
|
||||||
|
if ARCOLOGY_ENVIRONMENT != "production":
|
||||||
|
INSTALLED_APPS = ["localapi"] + INSTALLED_APPS
|
||||||
# The Arcology is Modular:1 ends here
|
# The Arcology is Modular:1 ends here
|
||||||
|
|
||||||
# [[file:../../configuration.org::*Internationalization][Internationalization:1]]
|
# [[file:../../configuration.org::*Internationalization][Internationalization:1]]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# [[file:../arcology.org::*The Web Server][The Web Server:1]]
|
# [[file:../arcology.org::*The Web Server][The Web Server:1]]
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, re_path, include
|
from django.urls import path, re_path, include
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from arcology import views
|
from arcology import views
|
||||||
|
|
||||||
|
@ -13,9 +14,12 @@ urlpatterns = [
|
||||||
path("feeds.json", views.feed_list, name="feed-list"),
|
path("feeds.json", views.feed_list, name="feed-list"),
|
||||||
path("", include("django_prometheus.urls")),
|
path("", include("django_prometheus.urls")),
|
||||||
path("", include("sitemap.urls")),
|
path("", include("sitemap.urls")),
|
||||||
path("api/v1/", include("localapi.urls")),
|
|
||||||
# ensure these ones are last because they're greedy!
|
# ensure these ones are last because they're greedy!
|
||||||
re_path("(?P<key>[0-9a-zA-Z/_\-]+\.xml)", views.feed, name="feed"),
|
re_path("(?P<key>[0-9a-zA-Z/_\-]+\.xml)", views.feed, name="feed"),
|
||||||
re_path("(?P<key>[0-9a-zA-Z/_\-]+)", views.org_page, name="org-page"),
|
re_path("(?P<key>[0-9a-zA-Z/_\-]+)", views.org_page, name="org-page"),
|
||||||
]
|
]
|
||||||
|
if settings.ARCOLOGY_ENVIRONMENT != "production":
|
||||||
|
urlpatterns = [
|
||||||
|
path("api/v1/", include("localapi.urls")),
|
||||||
|
] + urlpatterns
|
||||||
# The Web Server:1 ends here
|
# The Web Server:1 ends here
|
||||||
|
|
|
@ -286,7 +286,6 @@ basically, each org file in this repository, and maybe one or two of your own, a
|
||||||
| "generators" | [[id:arroyo/django/generators][The Arroyo Generators]] |
|
| "generators" | [[id:arroyo/django/generators][The Arroyo Generators]] |
|
||||||
| "syncthonk" | [[id:20231218T183551.765340][Arcology watchsync Command]] |
|
| "syncthonk" | [[id:20231218T183551.765340][Arcology watchsync Command]] |
|
||||||
| "sitemap" | [[id:20240226T132507.817450][The Arcology's Site Maps and Discovery Mechanisms]] |
|
| "sitemap" | [[id:20240226T132507.817450][The Arcology's Site Maps and Discovery Mechanisms]] |
|
||||||
| "localapi" | [[id:20240313T153901.656967][A Localhost API for the Arcology]] |
|
|
||||||
|
|
||||||
#+BEGIN_SRC python :tangle arcology/settings/__init__.py :noweb yes
|
#+BEGIN_SRC python :tangle arcology/settings/__init__.py :noweb yes
|
||||||
# Application definition
|
# Application definition
|
||||||
|
@ -301,6 +300,8 @@ INSTALLED_APPS = [
|
||||||
"django.contrib.messages",
|
"django.contrib.messages",
|
||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
]
|
]
|
||||||
|
if ARCOLOGY_ENVIRONMENT != "production":
|
||||||
|
INSTALLED_APPS = ["localapi"] + INSTALLED_APPS
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
** Internationalization
|
** Internationalization
|
||||||
|
|
36
localapi.org
36
localapi.org
|
@ -13,12 +13,14 @@ I think it's worth building a small HTTP JSON API which can serve some of the co
|
||||||
|
|
||||||
Here's how to use this from Emacs Lisp:
|
Here's how to use this from Emacs Lisp:
|
||||||
|
|
||||||
- =(arcology-localapi-call method path)= is an API helper which given an API path will fetch the data and return a deserialized JSON structure
|
- =(arcology-fetch-localapi-bearer-token)= fetches the bearer token file shared with the =localapi= deployment.
|
||||||
|
- =(arcology-localapi-call method path)= is an API helper which given an API path will fetch the data with authorization and return a deserialized JSON structure
|
||||||
- these interactive commands will fetch a URL, putting it on your kill ring or clipboard if you call it with =M-x= or equivalent:
|
- these interactive commands will fetch a URL, putting it on your kill ring or clipboard if you call it with =M-x= or equivalent:
|
||||||
- =(arcology-key-to-url page-key &optional heading-id)= will take an =ARCOLOGY_KEY= and return a URL
|
- =(arcology-key-to-url page-key &optional heading-id)= will take an =ARCOLOGY_KEY= and return a URL
|
||||||
- =(arcology-file-to-url file-path &optional heading-id)= will do the same with a file path from =(buffer-file-name)= or so.
|
- =(arcology-file-to-url file-path &optional heading-id)= will do the same with a file path from =(buffer-file-name)= or so.
|
||||||
- =(arcology-url-at-point)= gets the org-id of the heading your cursor is in if it has one, and makes a URL that links directly to that.
|
- =(arcology-url-at-point)= gets the org-id of the heading your cursor is in if it has one, and makes a URL that links directly to that.
|
||||||
- =(arcology-read-url)= pops up a list of all the org-roam headings, and returns a URL to it.
|
- =(arcology-read-url)= pops up a list of all the org-roam headings, and returns a URL to it.
|
||||||
|
- =(arcology-api-generator)= calls in to [[id:arroyo/django/generators][The Arroyo Generators]] and returns the string of files they generate
|
||||||
|
|
||||||
* Server view and Arroyo Emacs lisp scaffolding
|
* Server view and Arroyo Emacs lisp scaffolding
|
||||||
|
|
||||||
|
@ -31,13 +33,17 @@ The API will be simple, with a bearer token provided by a local state file:
|
||||||
|
|
||||||
(defun arcology-fetch-localapi-bearer-token ()
|
(defun arcology-fetch-localapi-bearer-token ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(customize-save-variable
|
(let ((tok (or arcology-localapi-bearer-token
|
||||||
'arcology-localapi-bearer-token
|
(getenv "ARCOLOGY_LOCALAPI_BEARER_TOKEN")
|
||||||
(or (getenv "ARCOLOGY_LOCALAPI_BEARER_TOKEN")
|
(thread-last
|
||||||
(thread-last
|
"~/sync/private-files/.arcology-env"
|
||||||
". ~/sync/private-files/.arcology-env && echo $ARCOLOGY_LOCALAPI_BEARER_TOKEN"
|
(format ". %s && echo $ARCOLOGY_LOCALAPI_BEARER_TOKEN")
|
||||||
(shell-command-to-string)
|
(shell-command-to-string)
|
||||||
(s-chop-suffix "\n" )))))
|
(s-chop-suffix "\n" )))))
|
||||||
|
(when (or (called-interactively-p)
|
||||||
|
(not arcology-localapi-bearer-token))
|
||||||
|
(customize-save-variable 'arcology-localapi-bearer-token tok))
|
||||||
|
tok))
|
||||||
|
|
||||||
(defcustom arcology-api-base "http://127.0.0.1:29543/api/v1"
|
(defcustom arcology-api-base "http://127.0.0.1:29543/api/v1"
|
||||||
"localapi base url")
|
"localapi base url")
|
||||||
|
@ -45,7 +51,7 @@ The API will be simple, with a bearer token provided by a local state file:
|
||||||
(defun arcology-localapi-call (method path &rest plz-args)
|
(defun arcology-localapi-call (method path &rest plz-args)
|
||||||
(let ((plz-args (or plz-args '(:as json-read))))
|
(let ((plz-args (or plz-args '(:as json-read))))
|
||||||
(apply 'plz method (format "%s%s" arcology-api-base path)
|
(apply 'plz method (format "%s%s" arcology-api-base path)
|
||||||
:headers `(("Authorization" . ,(format "Bearer %s" arcology-localapi-bearer-token)))
|
:headers `(("Authorization" . ,(format "Bearer %s" (arcology-fetch-localapi-bearer-token))))
|
||||||
plz-args)))
|
plz-args)))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
@ -370,11 +376,11 @@ let
|
||||||
arcology = cfg.packages.arcology;
|
arcology = cfg.packages.arcology;
|
||||||
|
|
||||||
env = [
|
env = [
|
||||||
|
"ARCOLOGY_ENVIRONMENT=development"
|
||||||
"ARCOLOGY_BASE_DIR=${cfg.orgDir}"
|
"ARCOLOGY_BASE_DIR=${cfg.orgDir}"
|
||||||
"ARCOLOGY_DB_PATH=${cfg.dataDir}/db.sqlite3"
|
"ARCOLOGY_DB_PATH=${cfg.dataDir}/db.sqlite3"
|
||||||
"ARCOLOGY_LOG_LEVEL=${cfg.logLevel}"
|
"ARCOLOGY_LOG_LEVEL=${cfg.logLevel}"
|
||||||
"ARCOLOGY_CACHE_PATH=${cfg.cacheDir}"
|
"ARCOLOGY_CACHE_PATH=${cfg.cacheDir}"
|
||||||
"GUNICORN_CMD_ARGS='--bind=${cfg.address}:${toString cfg.port} -w ${toString cfg.workerCount}'"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
pyenv = pkgs.python3.withPackages(pp: [arcology]);
|
pyenv = pkgs.python3.withPackages(pp: [arcology]);
|
||||||
|
@ -388,7 +394,7 @@ let
|
||||||
${arcology}/bin/arcology watchsync -f ${cfg.folderId}
|
${arcology}/bin/arcology watchsync -f ${cfg.folderId}
|
||||||
'';
|
'';
|
||||||
localapiScript = pkgs.writeScriptBin "arcology-localapi" ''
|
localapiScript = pkgs.writeScriptBin "arcology-localapi" ''
|
||||||
${pyenv}/bin/python -m gunicorn arcology.wsgi
|
${arcology}/bin/arcology runserver ${toString cfg.address}:${toString cfg.port}
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
options.services.arcology2 = with lib; {
|
options.services.arcology2 = with lib; {
|
||||||
|
|
Loading…
Reference in New Issue