feat: 修改docs的url

This commit is contained in:
ibuler 2020-06-03 11:17:00 +08:00
parent 96551856a2
commit 7c479c2479
2 changed files with 18 additions and 13 deletions

View File

@ -67,14 +67,14 @@ if settings.XPACK_ENABLED:
) )
js_i18n_patterns = i18n_patterns( js_i18n_patterns = i18n_patterns(
# path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'), path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'),
) )
apps = [ apps = [
'users', 'assets', 'perms', 'terminal', 'ops', 'audits', 'orgs', 'auth', 'users', 'assets', 'perms', 'terminal', 'ops', 'audits', 'orgs', 'auth',
'applications', 'tickets', 'settings', 'xpack' 'applications', 'tickets', 'settings', 'xpack'
'flower', 'luna', 'koko', 'ws', 'i18n', 'jsi18n', 'docs', 'redocs', 'flower', 'luna', 'koko', 'ws', 'docs', 'redocs',
] ]
@ -94,23 +94,25 @@ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += js_i18n_patterns urlpatterns += js_i18n_patterns
# 兼容之前的
old_app_pattern = '|'.join(apps)
urlpatterns += [re_path(old_app_pattern, views.redirect_old_apps_view)]
handler404 = 'jumpserver.views.handler404' handler404 = 'jumpserver.views.handler404'
handler500 = 'jumpserver.views.handler500' handler500 = 'jumpserver.views.handler500'
if settings.DEBUG: if settings.DEBUG:
app_view_patterns += [ urlpatterns += [
re_path('^swagger(?P<format>\.json|\.yaml)$', re_path('^api/swagger(?P<format>\.json|\.yaml)$',
views.get_swagger_view().without_ui(cache_timeout=1), name='schema-json'), views.get_swagger_view().without_ui(cache_timeout=1), name='schema-json'),
path('docs/', views.get_swagger_view().with_ui('swagger', cache_timeout=1), name="docs"), path('api/docs/', views.get_swagger_view().with_ui('swagger', cache_timeout=1), name="docs"),
path('redoc/', views.get_swagger_view().with_ui('redoc', cache_timeout=1), name='redoc'), path('api/redoc/', views.get_swagger_view().with_ui('redoc', cache_timeout=1), name='redoc'),
re_path('^v2/swagger(?P<format>\.json|\.yaml)$', re_path('^api/v2/swagger(?P<format>\.json|\.yaml)$',
views.get_swagger_view().without_ui(cache_timeout=1), name='schema-json'), views.get_swagger_view().without_ui(cache_timeout=1), name='schema-json'),
path('docs/v2/', views.get_swagger_view("v2").with_ui('swagger', cache_timeout=1), name="docs"), path('api/docs/v2/', views.get_swagger_view("v2").with_ui('swagger', cache_timeout=1), name="docs"),
path('redoc/v2/', views.get_swagger_view("v2").with_ui('redoc', cache_timeout=1), name='redoc'), path('api/redoc/v2/', views.get_swagger_view("v2").with_ui('redoc', cache_timeout=1), name='redoc'),
] ]
# 兼容之前的
old_app_pattern = '|'.join(apps)
urlpatterns += [re_path(old_app_pattern, views.redirect_old_apps_view)]

View File

@ -6,6 +6,7 @@ import time
from django.http import HttpResponseRedirect, JsonResponse, Http404 from django.http import HttpResponseRedirect, JsonResponse, Http404
from django.conf import settings from django.conf import settings
from django.views.generic import View from django.views.generic import View
from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.views import APIView from rest_framework.views import APIView
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
@ -55,6 +56,8 @@ def redirect_old_apps_view(request, *args, **kwargs):
path = request.get_full_path() path = request.get_full_path()
if path.find('/core') != -1: if path.find('/core') != -1:
raise Http404() raise Http404()
if path in ['/docs/', '/docs', '/core/docs/', '/core/docs']:
return redirect('/api/docs/')
new_path = '/core{}'.format(path) new_path = '/core{}'.format(path)
return HttpResponseTemporaryRedirect(new_path) return HttpResponseTemporaryRedirect(new_path)