-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (29 loc) · 959 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
let express = require("express");
let app = express();
const { glob } = require("glob");
const { promisify } = require("util");
const globPromise = promisify(glob);
app.set("view engine", "ejs");
app.use(express.static("public"));
app.disable("x-powered-by");
let apis = [];
async function load() {
let paths = await globPromise(`${process.cwd()}/apis/**/*.js`);
paths.forEach((path) => {
let file = require(path);
let conf = {};
if(file.help.category) conf[`${file.help.category}`][`${file.help.name}`] = file.help;
conf[file.help.name] = file.help
apis.push(conf);
app.use(`/${file.help.category}/${file.help.name}`, file.router);
});
}
load();
app.get("/", (req, res) => {
res.header("Content-Type", "application/json");
if (req.method === "GET") res.status(200).send(JSON.stringify(apis, null, 2));
});
app.get("/docs", (req, res) => {
res.render("index", { api: api });
});
app.listen(process.env.PORT || 3000);