-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
48 lines (36 loc) · 1.1 KB
/
index.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
import express from "express";
import cors from "cors";
import fs from "fs";
import mongoose from "mongoose";
import logger from "./middleware/logger";
mongoose.connect(process.env.MONGO_URI);
mongoose.connection.on("connected", () => {
console.log("Server connected to MongoDB");
});
const app = express();
app.use(cors());
app.use(express.json())
app.use(logger())
app.use("/", express.static("reference"));
app.use("/assets", express.static("assets"));
app.use("/oauth", express.static("oauth"));
app.use("/dist", express.static("dist"));
let CODES = {};
function recFilesPaths(rootPath: string) {
let directSubPaths = fs.readdirSync(rootPath)
.map(path => rootPath + "/" + path);
let filePaths = [];
for(let subPath of directSubPaths) {
if(fs.lstatSync(subPath).isDirectory()) {
filePaths = filePaths.concat(recFilesPaths(subPath));
} else filePaths.push(subPath);
}
return filePaths;
}
for(let endpoint of recFilesPaths("./routes")) {
let { run } = await import(endpoint);
run(app, CODES);
}
app.listen(8080, () => {
console.log(`Server listening to port ${8080}`);
});