An open source, non-profit web search engine
Duplicate the API at /api/v1/
Daoud Clarkef883ea9f7acc
diff --git a/mwmbl/api.py b/mwmbl/api.pyindex 713bfc3..4a9cf08 100644--- a/mwmbl/api.py+++ b/mwmbl/api.py@@ -12,20 +12,28 @@ from mwmbl.tinysearchengine.completer import Completerfrom mwmbl.tinysearchengine.indexer import TinyIndex, Documentfrom mwmbl.tinysearchengine.rank import HeuristicRanker-api = NinjaAPI(version="1.0.0")++queued_batches = Queue()+completer = Completer()index_path = Path(settings.DATA_PATH) / INDEX_NAMEtiny_index = TinyIndex(item_factory=Document, index_path=index_path)tiny_index.__enter__()--completer = Completer()ranker = HeuristicRanker(tiny_index, completer)+batch_cache = BatchCache(Path(settings.DATA_PATH) / BATCH_DIR_NAME)-search_router = search.create_router(ranker)-api.add_router("/search/", search_router)-batch_cache = BatchCache(Path(settings.DATA_PATH) / BATCH_DIR_NAME)+def create_api(version):+ api = NinjaAPI(version=version)-queued_batches = Queue()-crawler_router = crawler.create_router(batch_cache=batch_cache, queued_batches=queued_batches)-api.add_router("/crawler/", crawler_router)+ 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")diff --git a/mwmbl/settings_common.py b/mwmbl/settings_common.pyindex 35b2ffb..645ebd4 100644--- a/mwmbl/settings_common.py+++ b/mwmbl/settings_common.py@@ -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 definitiondiff --git a/mwmbl/settings_dev.py b/mwmbl/settings_dev.pyindex 68d01b0..d0c255b 100644--- a/mwmbl/settings_dev.py+++ b/mwmbl/settings_dev.py@@ -1,6 +1,7 @@from mwmbl.settings_common import *DEBUG = True+ALLOWED_HOSTS = ["localhost", "127.0.0.1"]DATA_PATH = "./devdata"RUN_BACKGROUND_PROCESSES = Falsediff --git a/mwmbl/settings_prod.py b/mwmbl/settings_prod.pyindex 780309c..31fe52d 100644--- a/mwmbl/settings_prod.py+++ b/mwmbl/settings_prod.py@@ -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 = Truediff --git a/mwmbl/urls.py b/mwmbl/urls.pyindex ff67f2d..7d8bff6 100644--- a/mwmbl/urls.py+++ b/mwmbl/urls.py@@ -17,9 +17,10 @@ Including another URLconffrom django.contrib import adminfrom django.urls import path-from mwmbl.api import api+from mwmbl.api import api_original as api, api_v1urlpatterns = [path('admin/', admin.site.urls),- path('', api.urls)+ path('', api.urls),+ path('api/v1/', api_v1.urls)]