urls.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from .admin import archivebox_admin
  2. from django.urls import path, include
  3. from django.views import static
  4. from django.contrib.staticfiles.urls import staticfiles_urlpatterns
  5. from django.conf import settings
  6. from django.views.generic.base import RedirectView
  7. from core.views import HomepageView, SnapshotView, PublicIndexView, AddView, HealthCheckView
  8. from ninja import NinjaAPI
  9. from api.auth import GlobalAuth
  10. api = NinjaAPI(auth=GlobalAuth())
  11. api.add_router("/auth/", "api.auth.router")
  12. api.add_router("/archive/", "api.archive.router")
  13. # GLOBAL_CONTEXT doesn't work as-is, disabled for now: https://github.com/ArchiveBox/ArchiveBox/discussions/1306
  14. # from config import VERSION, VERSIONS_AVAILABLE, CAN_UPGRADE
  15. # GLOBAL_CONTEXT = {'VERSION': VERSION, 'VERSIONS_AVAILABLE': VERSIONS_AVAILABLE, 'CAN_UPGRADE': CAN_UPGRADE}
  16. # print('DEBUG', settings.DEBUG)
  17. urlpatterns = [
  18. path('public/', PublicIndexView.as_view(), name='public-index'),
  19. path('robots.txt', static.serve, {'document_root': settings.STATICFILES_DIRS[0], 'path': 'robots.txt'}),
  20. path('favicon.ico', static.serve, {'document_root': settings.STATICFILES_DIRS[0], 'path': 'favicon.ico'}),
  21. path('docs/', RedirectView.as_view(url='https://github.com/ArchiveBox/ArchiveBox/wiki'), name='Docs'),
  22. path('archive/', RedirectView.as_view(url='/')),
  23. path('archive/<path:path>', SnapshotView.as_view(), name='Snapshot'),
  24. path('web/<path:path>', SnapshotView.as_view()), # support archive.org-style URLs
  25. path('plugins/replaywebpage/', include('plugins.replaywebpage.urls')),
  26. # ... dynamic load these someday if there are more of them
  27. path('admin/core/snapshot/add/', RedirectView.as_view(url='/add/')),
  28. path('add/', AddView.as_view(), name='add'),
  29. path('accounts/login/', RedirectView.as_view(url='/admin/login/')),
  30. path('accounts/logout/', RedirectView.as_view(url='/admin/logout/')),
  31. path('accounts/', include('django.contrib.auth.urls')),
  32. path('admin/', archivebox_admin.urls),
  33. path("api/", api.urls),
  34. path('health/', HealthCheckView.as_view(), name='healthcheck'),
  35. path('error/', lambda _: 1/0),
  36. # path('jet_api/', include('jet_django.urls')), Enable to use https://www.jetadmin.io/integrations/django
  37. path('index.html', RedirectView.as_view(url='/')),
  38. path('index.json', static.serve, {'document_root': settings.OUTPUT_DIR, 'path': 'index.json'}),
  39. path('', HomepageView.as_view(), name='Home'),
  40. ]
  41. urlpatterns += staticfiles_urlpatterns()
  42. if settings.DEBUG_TOOLBAR:
  43. import debug_toolbar
  44. urlpatterns += [
  45. path('__debug__/', include(debug_toolbar.urls)),
  46. ]
  47. # # Proposed FUTURE URLs spec
  48. # path('', HomepageView)
  49. # path('/add', AddView)
  50. # path('/public', PublicIndexView)
  51. # path('/snapshot/:slug', SnapshotView)
  52. # path('/admin', admin.site.urls)
  53. # path('/accounts', django.contrib.auth.urls)
  54. # # Prposed REST API spec
  55. # # :slugs can be uuid, short_uuid, or any of the unique index_fields
  56. # path('api/v1/'),
  57. # path('api/v1/core/' [GET])
  58. # path('api/v1/core/snapshot/', [GET, POST, PUT]),
  59. # path('api/v1/core/snapshot/:slug', [GET, PATCH, DELETE]),
  60. # path('api/v1/core/archiveresult', [GET, POST, PUT]),
  61. # path('api/v1/core/archiveresult/:slug', [GET, PATCH, DELETE]),
  62. # path('api/v1/core/tag/', [GET, POST, PUT]),
  63. # path('api/v1/core/tag/:slug', [GET, PATCH, DELETE]),
  64. # path('api/v1/cli/', [GET])
  65. # path('api/v1/cli/{add,list,config,...}', [POST]), # pass query as kwargs directly to `run_subcommand` and return stdout, stderr, exitcode
  66. # path('api/v1/extractors/', [GET])
  67. # path('api/v1/extractors/:extractor/', [GET]),
  68. # path('api/v1/extractors/:extractor/:func', [GET, POST]), # pass query as args directly to chosen function
  69. # future, just an idea:
  70. # path('api/v1/scheduler/', [GET])
  71. # path('api/v1/scheduler/task/', [GET, POST, PUT]),
  72. # path('api/v1/scheduler/task/:slug', [GET, PATCH, DELETE]),