ProxmoxAAS-API/src/main.js

76 lines
1.8 KiB
JavaScript
Raw Normal View History

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";
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: {
localdb: "config/localdb.json"
}
});
global.api = api;
global.pve = pve;
global.utils = utils;
2023-08-03 19:51:09 +00:00
global.db = new LocalDB(global.argv.localdb);
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 }));
app.use(morgan("combined"));
2023-08-03 19:51:09 +00:00
global.server = app.listen(global.db.listenPort, () => {
2023-08-03 19:34:37 +00:00
console.log(`proxmoxaas-api v${api.version} listening on port ${global.db.listenPort}`);
});
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);
});
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
/**
* GET - get API version
2023-07-06 05:13:22 +00:00
* responses:
* - 200: {version: string}
2023-07-06 05:13:22 +00:00
*/
app.get("/api/version", (req, res) => {
res.status(200).send({ version: api.version });
2023-07-06 05:13:22 +00:00
});
/**
* GET - echo request
2023-07-06 05:13:22 +00:00
* responses:
* - 200: {body: request.body, cookies: request.cookies}
2023-07-06 05:13:22 +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
});