import * as express from "express";
import AdminRoute from "./admin";
import UserRoute from "./user";
import InternalRoute from "./internal";
import Login from "./user/login";
import ClientRouter from "./client";
import * as cors from "cors";
import OAuthRoute from "./oauth";
import config from "../config";

const ApiRouter: express.IRouter = express.Router();
ApiRouter.use("/admin", AdminRoute);
ApiRouter.use(cors());
ApiRouter.use("/user", UserRoute);
ApiRouter.use("/internal", InternalRoute);
ApiRouter.use("/oauth", OAuthRoute);

ApiRouter.use("/client", ClientRouter);

// Legacy reasons (deprecated)
ApiRouter.use("/", ClientRouter);

// Legacy reasons (deprecated)
ApiRouter.post("/login", Login);

ApiRouter.get("/config.json", (req, res) => {
   return res.json({
      name: config.core.name,
      url: config.core.url,
   });
});

export default ApiRouter;
