diff --git a/mwmbl/api.py b/mwmbl/api.py index 713bfc3..4a9cf08 100644 --- a/mwmbl/api.py +++ b/mwmbl/api.py @@ -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") diff --git a/mwmbl/settings_common.py b/mwmbl/settings_common.py index 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 definition diff --git a/mwmbl/settings_dev.py b/mwmbl/settings_dev.py index 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 = False diff --git a/mwmbl/settings_prod.py b/mwmbl/settings_prod.py index 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 = True diff --git a/mwmbl/urls.py b/mwmbl/urls.py index ff67f2d..7d8bff6 100644 --- a/mwmbl/urls.py +++ b/mwmbl/urls.py @@ -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) ]