diff --git a/mwmbl/api.py b/mwmbl/api.py index 713bfc357a863d61404f775c3adce3aebe21e2d7..4a9cf0837036355fe97d711e092a5c9c81de01a4 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) +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.py index 35b2ffb1c1c8a4ae4b758fb9a6978a85da3a3b70..645ebd46f956dd7db592268325ff48c20edefbb0 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 68d01b0026861d149349bd98f433d3078bff55d3..d0c255b42bcb84608a29b50cb9b7f1c4e257217f 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 780309c5996f782aed32bd8f07728909d8e63bee..31fe52d654adf2d5aa696cc66b0beccf88ecc719 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 ff67f2d744c0896a36599db8cbf8102f6faf3c1e..7d8bff6bf3d9e157e621fc9914158a0e9d5a6355 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) ]