2024-08-03 15:19:39 +00:00
|
|
|
"use strict";
|
2019-04-15 10:13:17 +00:00
|
|
|
|
2024-08-03 15:19:39 +00:00
|
|
|
const express = require("express");
|
|
|
|
|
const glob = require("glob");
|
|
|
|
|
const path = require("path");
|
|
|
|
|
const { apicache } = require("../middlewares/cache");
|
2019-04-15 10:13:17 +00:00
|
|
|
|
2024-08-03 15:19:39 +00:00
|
|
|
const modulesDir = path.resolve(__dirname + "/../modules/");
|
2019-04-15 10:13:17 +00:00
|
|
|
const globOptions = {
|
2024-08-03 15:19:39 +00:00
|
|
|
cwd: modulesDir,
|
|
|
|
|
nocase: true,
|
|
|
|
|
nodir: true,
|
|
|
|
|
absolute: true,
|
|
|
|
|
};
|
2019-07-28 20:08:15 +00:00
|
|
|
|
2019-04-15 15:58:58 +00:00
|
|
|
module.exports = function () {
|
2024-08-03 15:19:39 +00:00
|
|
|
const router = express.Router({ mergeParams: true });
|
2019-07-28 20:08:15 +00:00
|
|
|
|
2024-08-03 15:19:39 +00:00
|
|
|
router.get("/v3/_health", (req, res, next) => {
|
|
|
|
|
res.json({
|
|
|
|
|
code: 200,
|
|
|
|
|
message: "success",
|
|
|
|
|
description: "Welcome, this is the API v3 for the application.",
|
2019-07-28 20:08:15 +00:00
|
|
|
});
|
2024-08-03 15:19:39 +00:00
|
|
|
});
|
2019-07-28 20:08:15 +00:00
|
|
|
|
2024-08-03 15:19:39 +00:00
|
|
|
// APICACHE
|
2019-07-28 20:08:15 +00:00
|
|
|
|
2024-08-03 15:19:39 +00:00
|
|
|
// route to display cache index
|
|
|
|
|
router.get("/v3/cache/index", (req, res) => {
|
|
|
|
|
res.json(apicache.getIndex());
|
|
|
|
|
});
|
2019-07-28 20:08:15 +00:00
|
|
|
|
2024-08-03 15:19:39 +00:00
|
|
|
// route to clear target group
|
|
|
|
|
router.get("/v3/cache/clear/:target?", (req, res) => {
|
|
|
|
|
res.json(apicache.clear(req.params.target));
|
|
|
|
|
});
|
2022-03-16 09:08:33 +00:00
|
|
|
|
2024-08-03 15:19:39 +00:00
|
|
|
// Resto de rutas
|
2019-04-15 10:13:17 +00:00
|
|
|
|
2024-08-08 17:32:41 +00:00
|
|
|
glob.sync("**/*.routes.js", globOptions).forEach(function (file) {
|
|
|
|
|
router.use("/v3", require(file));
|
|
|
|
|
});
|
2019-04-15 10:13:17 +00:00
|
|
|
|
2024-08-03 15:19:39 +00:00
|
|
|
glob.sync("**/*.routes.v4.js", globOptions).forEach(function (file) {
|
|
|
|
|
router.use("/v4", require(file));
|
|
|
|
|
});
|
2019-04-15 10:13:17 +00:00
|
|
|
|
2024-08-03 15:19:39 +00:00
|
|
|
return router;
|
|
|
|
|
};
|