~app/routes.tsx
.ts
TypeScript
(application/typescript)
// 1st-party
import { AppRouter, AppRouterGroup, Router } from "@ethicdevs/react-monolith";
// 3rd-party
import React from "react";
// app
import { AppRoute, AppRoutePaths, AppRouteSchemas } from "./routes.defs";
import { authenticatedOrLogin, guestOrRedirect } from "./utils/server";
// app controllers
import {
  AuthController,
  HomeController,
  OrganizationController,
  RepositoryController,
  RepositoryPullRequestsController,
  SyntaxHighlightController,
  ThemeController,
  UserController,
} from "./controllers";

const RootAppRouter: AppRouter = () => {
  const loggedOrLoginRedirect = authenticatedOrLogin();
  const guestOrDashboardRedirect = guestOrRedirect(
    AppRoutePaths[AppRoute.USER_DASHBOARD]
  );

  return (
    <Router.Root>
      <></>
      <Router.Group type={AppRouterGroup.API}>
        <Router.Route
          name={AppRoute.THEME_SET_SCHEME_ACTION}
          method={"GET"}
          path={AppRoutePaths[AppRoute.THEME_SET_SCHEME_ACTION]}
          schema={AppRouteSchemas[AppRoute.THEME_SET_SCHEME_ACTION]}
          handler={ThemeController.setThemeSchemeAction}
        />
        {/* --- */}
        <Router.Route
          name={AppRoute.HOME}
          method={"GET"}
          path={AppRoutePaths[AppRoute.HOME]}
          preHandler={guestOrDashboardRedirect}
          handler={HomeController.getHomeView}
        />
        {/* --- */}
        <Router.Route
          name={AppRoute.AUTH_REGISTER}
          method={"GET"}
          path={AppRoutePaths[AppRoute.AUTH_REGISTER]}
          preHandler={guestOrDashboardRedirect}
          handler={AuthController.getRegisterView}
        />
        <Router.Route
          name={AppRoute.AUTH_REGISTER_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.AUTH_REGISTER_ACTION]}
          preHandler={guestOrDashboardRedirect}
          schema={AppRouteSchemas[AppRoute.AUTH_REGISTER_ACTION]}
          handler={AuthController.postRegisterAction}
        />
        {/* --- */}
        <Router.Route
          name={AppRoute.AUTH_LOGIN}
          method={"GET"}
          path={AppRoutePaths[AppRoute.AUTH_LOGIN]}
          preHandler={guestOrDashboardRedirect}
          schema={AppRouteSchemas[AppRoute.AUTH_LOGIN]}
          handler={AuthController.getLoginView}
        />
        <Router.Route
          name={AppRoute.AUTH_LOGIN_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.AUTH_LOGIN_ACTION]}
          preHandler={guestOrDashboardRedirect}
          schema={AppRouteSchemas[AppRoute.AUTH_LOGIN_ACTION]}
          handler={AuthController.postLoginAction}
        />
        <Router.Route
          name={AppRoute.AUTH_LOGOUT_ACTION}
          method={"GET"}
          path={AppRoutePaths[AppRoute.AUTH_LOGOUT_ACTION]}
          preHandler={loggedOrLoginRedirect}
          schema={AppRouteSchemas[AppRoute.AUTH_LOGOUT_ACTION]}
          handler={AuthController.getLogoutAction}
        />
        {/* --- */}
        <Router.Route
          name={AppRoute.USER_DASHBOARD}
          method={"GET"}
          path={AppRoutePaths[AppRoute.USER_DASHBOARD]}
          preHandler={loggedOrLoginRedirect}
          handler={UserController.getUserDashboardView}
        />
        <Router.Route
          name={AppRoute.USER_DETAILS}
          method={"GET"}
          path={AppRoutePaths[AppRoute.USER_DETAILS]}
          handler={UserController.getUserDetailsView}
        />
        {/* --- */}
        <Router.Route
          name={AppRoute.ORGANIZATION_DETAILS}
          method={"GET"}
          path={AppRoutePaths[AppRoute.ORGANIZATION_DETAILS]}
          schema={AppRouteSchemas[AppRoute.ORGANIZATION_DETAILS]}
          handler={OrganizationController.getOrganizationDetailsView}
        />
        {/* --- */}
        <Router.Route
          name={AppRoute.REPOSITORY_BROWSER}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_BROWSER]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_BROWSER]}
          handler={RepositoryController.getRepositoryBrowserView}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_BROWSER_WITH_PATH}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_BROWSER_WITH_PATH]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_BROWSER]}
          handler={RepositoryController.getRepositoryBrowserView}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_COMMITS_LOG}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_COMMITS_LOG]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_COMMITS_LOG]}
          handler={RepositoryController.getRepositoryCommitsLogView}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_COMPARE}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_COMPARE]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_COMPARE]}
          handler={RepositoryController.getRepositoryCompareView}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_CREATE}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_CREATE]}
          preHandler={loggedOrLoginRedirect}
          handler={RepositoryController.getRepositoryCreateView}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_CREATE_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.REPOSITORY_CREATE_ACTION]}
          preHandler={loggedOrLoginRedirect}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_CREATE_ACTION]}
          handler={RepositoryController.postRepositoryCreateAction}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_DETAILS}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_DETAILS]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_DETAILS]}
          handler={RepositoryController.getRepositoryDetailsView}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_DETAILS_WITH_TRAILING_SLASH}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_DETAILS_WITH_TRAILING_SLASH]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_DETAILS]}
          handler={RepositoryController.getRepositoryDetailsView}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_EXPLORE}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_EXPLORE]}
          handler={RepositoryController.getRepositoryExploreView}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_FORK}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_FORK]}
          preHandler={loggedOrLoginRedirect}
          handler={RepositoryController.getRepositoryForkView}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_FORK_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.REPOSITORY_FORK_ACTION]}
          preHandler={loggedOrLoginRedirect}
          handler={RepositoryController.postRepositoryForkAction}
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_CLOSE_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.REPOSITORY_PULL_REQUEST_CLOSE_ACTION]}
          schema={
            AppRouteSchemas[AppRoute.REPOSITORY_PULL_REQUEST_CLOSE_ACTION]
          }
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.getRepositoryPullRequestCloseAction
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_CREATE_ACTION}
          method={"POST"}
          path={
            AppRoutePaths[
              AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_CREATE_ACTION
            ]
          }
          schema={
            AppRouteSchemas[
              AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_CREATE_ACTION
            ]
          }
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.getRepositoryPullRequestCommentCreateAction
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_DELETE_ACTION}
          method={"POST"}
          path={
            AppRoutePaths[
              AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_DELETE_ACTION
            ]
          }
          schema={
            AppRouteSchemas[
              AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_DELETE_ACTION
            ]
          }
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.getRepositoryPullRequestCommentDeleteAction
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_UPDATE_ACTION}
          method={"POST"}
          path={
            AppRoutePaths[
              AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_UPDATE_ACTION
            ]
          }
          schema={
            AppRouteSchemas[
              AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_UPDATE_ACTION
            ]
          }
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.getRepositoryPullRequestCommentUpdateAction
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_CREATE}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_PULL_REQUEST_CREATE]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_PULL_REQUEST_CREATE]}
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.getRepositoryPullRequestCreateView
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_CREATE_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.REPOSITORY_PULL_REQUEST_CREATE_ACTION]}
          schema={
            AppRouteSchemas[AppRoute.REPOSITORY_PULL_REQUEST_CREATE_ACTION]
          }
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.postRepositoryPullRequestCreateAction
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_DELETE_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.REPOSITORY_PULL_REQUEST_DELETE_ACTION]}
          schema={
            AppRouteSchemas[AppRoute.REPOSITORY_PULL_REQUEST_DELETE_ACTION]
          }
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.getRepositoryPullRequestDeleteAction
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_DETAILS}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_PULL_REQUEST_DETAILS]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_PULL_REQUEST_DETAILS]}
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.getRepositoryPullRequestDetailsView
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_MERGE_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.REPOSITORY_PULL_REQUEST_MERGE_ACTION]}
          schema={
            AppRouteSchemas[AppRoute.REPOSITORY_PULL_REQUEST_MERGE_ACTION]
          }
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.postRepositoryPullRequestMergeAction
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUEST_UPDATE_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.REPOSITORY_PULL_REQUEST_UPDATE_ACTION]}
          schema={
            AppRouteSchemas[AppRoute.REPOSITORY_PULL_REQUEST_UPDATE_ACTION]
          }
          preHandler={loggedOrLoginRedirect}
          handler={
            RepositoryPullRequestsController.getRepositoryPullRequestUpdateAction
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_PULL_REQUESTS}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_PULL_REQUESTS]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_PULL_REQUESTS]}
          handler={
            RepositoryPullRequestsController.getRepositoryPullRequestsView
          }
        />
        <Router.Route
          name={AppRoute.REPOSITORY_SHOW_OBJECT}
          method={"GET"}
          path={AppRoutePaths[AppRoute.REPOSITORY_SHOW_OBJECT]}
          schema={AppRouteSchemas[AppRoute.REPOSITORY_SHOW_OBJECT]}
          handler={RepositoryController.getRepositoryShowObjectView}
        />
        {/* --- */}
        <Router.Route
          name={AppRoute.SYNTAX_HIGHLIGHT_HIGHLIGHT_CODE_ACTION}
          method={"POST"}
          path={AppRoutePaths[AppRoute.SYNTAX_HIGHLIGHT_HIGHLIGHT_CODE_ACTION]}
          schema={
            AppRouteSchemas[AppRoute.SYNTAX_HIGHLIGHT_HIGHLIGHT_CODE_ACTION]
          }
          handler={SyntaxHighlightController.highlightCodeAction}
        />
      </Router.Group>
    </Router.Root>
  );
};

export default RootAppRouter;