2023-07-06 05:13:22 +00:00
|
|
|
import express from "express";
|
|
|
|
import bodyParser from "body-parser";
|
|
|
|
import cookieParser from "cookie-parser";
|
|
|
|
import cors from "cors";
|
|
|
|
import morgan from "morgan";
|
|
|
|
|
2023-07-27 20:10:46 +00:00
|
|
|
import api from "./package.js";
|
|
|
|
import * as pve from "./pve.js";
|
|
|
|
import * as utils from "./utils.js";
|
2023-08-03 19:51:09 +00:00
|
|
|
import LocalDB from "./db.js";
|
2023-07-06 05:13:22 +00:00
|
|
|
|
2023-08-03 19:31:11 +00:00
|
|
|
import parseArgs from "minimist";
|
|
|
|
global.argv = parseArgs(process.argv.slice(2), {
|
|
|
|
default: {
|
2023-08-05 00:38:57 +00:00
|
|
|
package: "package.json",
|
2023-08-03 19:31:11 +00:00
|
|
|
localdb: "config/localdb.json"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-05 00:38:57 +00:00
|
|
|
global.api = api(global.argv.package);
|
2023-07-27 20:10:46 +00:00
|
|
|
global.pve = pve;
|
|
|
|
global.utils = utils;
|
2023-08-03 19:51:09 +00:00
|
|
|
global.db = new LocalDB(global.argv.localdb);
|
2023-07-27 20:10:46 +00:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
global.app = app;
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
|
|
app.use(cookieParser());
|
2023-08-03 19:51:09 +00:00
|
|
|
app.use(cors({ origin: global.db.hostname }));
|
2023-07-27 20:10:46 +00:00
|
|
|
app.use(morgan("combined"));
|
|
|
|
|
2023-08-03 19:51:09 +00:00
|
|
|
global.server = app.listen(global.db.listenPort, () => {
|
2023-08-05 00:38:57 +00:00
|
|
|
console.log(`proxmoxaas-api v${global.api.version} listening on port ${global.db.listenPort}`);
|
2023-07-27 20:10:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
import("./routes/auth.js").then((module) => {
|
|
|
|
app.use("/api/auth", module.router);
|
|
|
|
});
|
|
|
|
|
2023-08-01 19:07:45 +00:00
|
|
|
import("./routes/cluster.js").then((module) => {
|
2023-08-03 00:36:18 +00:00
|
|
|
app.use("/api/cluster", module.router);
|
2023-08-01 19:07:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
import("./routes/global.js").then((module) => {
|
|
|
|
app.use("/api/global", module.router);
|
|
|
|
});
|
|
|
|
|
2023-07-27 20:10:46 +00:00
|
|
|
import("./routes/proxmox.js").then((module) => {
|
|
|
|
app.use("/api/proxmox", module.router);
|
|
|
|
});
|
|
|
|
|
|
|
|
import("./routes/sync.js").then((module) => {
|
|
|
|
app.use("/api/sync", module.router);
|
|
|
|
});
|
|
|
|
|
|
|
|
import("./routes/user.js").then((module) => {
|
|
|
|
app.use("/api/user", module.router);
|
|
|
|
});
|
|
|
|
|
2023-07-06 05:13:22 +00:00
|
|
|
/**
|
2023-07-27 20:10:46 +00:00
|
|
|
* GET - get API version
|
2023-07-06 05:13:22 +00:00
|
|
|
* responses:
|
2023-07-27 20:10:46 +00:00
|
|
|
* - 200: {version: string}
|
2023-07-06 05:13:22 +00:00
|
|
|
*/
|
2023-07-27 20:10:46 +00:00
|
|
|
app.get("/api/version", (req, res) => {
|
2023-08-05 00:38:57 +00:00
|
|
|
res.status(200).send({ version: global.api.version });
|
2023-07-06 05:13:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2023-07-27 20:10:46 +00:00
|
|
|
* GET - echo request
|
2023-07-06 05:13:22 +00:00
|
|
|
* responses:
|
2023-07-27 20:10:46 +00:00
|
|
|
* - 200: {body: request.body, cookies: request.cookies}
|
2023-07-06 05:13:22 +00:00
|
|
|
*/
|
2023-07-27 20:10:46 +00:00
|
|
|
app.get("/api/echo", (req, res) => {
|
|
|
|
res.status(200).send({ body: req.body, cookies: req.cookies });
|
2023-07-06 05:13:22 +00:00
|
|
|
});
|