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";
|
|
|
|
import db from "./db.js";
|
2023-07-06 05:13:22 +00:00
|
|
|
|
2023-07-27 20:10:46 +00:00
|
|
|
global.api = api;
|
|
|
|
global.pve = pve;
|
|
|
|
global.utils = utils;
|
|
|
|
global.db = db;
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
global.app = app;
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
|
|
app.use(cookieParser());
|
|
|
|
app.use(cors({ origin: db.hostname }));
|
|
|
|
app.use(morgan("combined"));
|
|
|
|
|
|
|
|
global.server = app.listen(db.listenPort, () => {
|
|
|
|
console.log(`proxmoxaas-api v${api.version} listening on port ${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);
|
|
|
|
});
|
|
|
|
|
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) => {
|
|
|
|
res.status(200).send({ version: 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
|
|
|
});
|