Commit 2f19496e authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Unified the documentation paths for optimade and v1.

parent fc32f513
......@@ -17,7 +17,7 @@
#
from fastapi import FastAPI, status, Request
from fastapi.responses import JSONResponse
from fastapi.responses import JSONResponse, RedirectResponse
from fastapi.middleware.wsgi import WSGIMiddleware
import traceback
......@@ -32,8 +32,8 @@ logger = utils.get_logger(__name__)
app = FastAPI(
openapi_url='%s/api/v1/openapi.json' % config.services.api_base_path,
docs_url='%s/api/v1/docs' % config.services.api_base_path,
redoc_url='%s/api/v1/redoc' % config.services.api_base_path,
docs_url='%s/api/v1/extensions/docs' % config.services.api_base_path,
redoc_url='%s/api/v1/extensions/redoc' % config.services.api_base_path,
swagger_ui_oauth2_redirect_url='%s/api/v1/docs/oauth2-redirect' % config.services.api_base_path,
title='NOMAD API',
......@@ -114,6 +114,14 @@ app = FastAPI(
'''))
async def redirect_to_docs(req: Request):
return RedirectResponse('%s/api/v1/extensions/docs' % config.services.api_base_path)
app.add_route('%s/api/v1' % config.services.api_base_path, redirect_to_docs, include_in_schema=False)
app.add_route('%s/api/v1/' % config.services.api_base_path, redirect_to_docs, include_in_schema=False)
@app.on_event('startup')
async def startup_event():
from nomad import infrastructure
......
......@@ -12,10 +12,9 @@ sys.modules['optimade.server.logger'] = importlib.import_module('nomad.app_fasta
# patch optimade base path
from nomad import config, utils # nopep8
from optimade.server.config import CONFIG # nopep8
CONFIG.root_path = "%s/optimade" % config.services.api_base_path
CONFIG.root_path = '%s/optimade' % config.services.api_base_path
from optimade.server import main as optimade # nopep8
from optimade.server.main import app as optimade_app # nopep8
from optimade.server.routers import structures # nopep8
# remove all the test data
......@@ -59,3 +58,6 @@ def general_exception(request, exc, status_code=500, **kwargs):
setattr(exception_handlers, 'general_exception', general_exception)
# "export" the app object
optimade_app = optimade.app
#
# Copyright The NOMAD Authors.
#
......@@ -24,7 +25,7 @@ import elasticsearch
import sys
import threading
from nomad import processing as proc, search, datamodel, infrastructure, utils, config
from nomad import processing as proc, search, infrastructure, utils, config
from nomad.cli.cli import cli
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment