Merge pull request #118 from mwmbl/new-api-url

Duplicate the API at /api/v1/
This commit is contained in:
Daoud Clarke 2023-10-14 11:44:37 +01:00 committed by GitHub
commit 70c06b78da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 14 deletions

View file

@ -12,20 +12,28 @@ from mwmbl.tinysearchengine.completer import Completer
from mwmbl.tinysearchengine.indexer import TinyIndex, Document
from mwmbl.tinysearchengine.rank import HeuristicRanker
api = NinjaAPI(version="1.0.0")
queued_batches = Queue()
completer = Completer()
index_path = Path(settings.DATA_PATH) / INDEX_NAME
tiny_index = TinyIndex(item_factory=Document, index_path=index_path)
tiny_index.__enter__()
completer = Completer()
ranker = HeuristicRanker(tiny_index, completer)
search_router = search.create_router(ranker)
api.add_router("/search/", search_router)
batch_cache = BatchCache(Path(settings.DATA_PATH) / BATCH_DIR_NAME)
queued_batches = Queue()
crawler_router = crawler.create_router(batch_cache=batch_cache, queued_batches=queued_batches)
api.add_router("/crawler/", crawler_router)
def create_api(version):
api = NinjaAPI(version=version)
search_router = search.create_router(ranker)
api.add_router("/search/", search_router)
crawler_router = crawler.create_router(batch_cache=batch_cache, queued_batches=queued_batches)
api.add_router("/crawler/", crawler_router)
return api
# Work around because Django-Ninja doesn't allow using multiple URLs for the same thing
api_original = create_api("0.1")
api_v1 = create_api("1.0.0")

View file

@ -22,8 +22,6 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-qqr#f(i3uf%m8%8u35vn=ov-uk(*8!a&1t-hxa%ev2^t1%j&sm'
ALLOWED_HOSTS = ["api.mwmbl.org"]
# Application definition

View file

@ -1,6 +1,7 @@
from mwmbl.settings_common import *
DEBUG = True
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
DATA_PATH = "./devdata"
RUN_BACKGROUND_PROCESSES = False

View file

@ -1,6 +1,7 @@
from mwmbl.settings_common import *
DEBUG = False
ALLOWED_HOSTS = ["api.mwmbl.org", "en.mwmbl.org"]
DATA_PATH = "/app/storage"
RUN_BACKGROUND_PROCESSES = True

View file

@ -17,9 +17,10 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
from mwmbl.api import api
from mwmbl.api import api_original as api, api_v1
urlpatterns = [
path('admin/', admin.site.urls),
path('', api.urls)
path('', api.urls),
path('api/v1/', api_v1.urls)
]