-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
38 lines (36 loc) · 1.4 KB
/
main.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
36
37
38
const logReader = require("./logReader");
const getFilesInDependencyOrder = require("./GetFileInDependencyOrder");
const findExecutedPath = require("./findExecutedPath");
const app = require("express")();
let dependencyOrder;
let mainDirectoryPath = process.cwd().split("/");
mainDirectoryPath.splice(-2, 2);
mainDirectoryPath = mainDirectoryPath.join("/");
app.get("/jsnavigator", (req, res) => {
const queryParams = req.query;
dependencyOrder = getFilesInDependencyOrder(
`${mainDirectoryPath}/${queryParams.entry}`,
queryParams.importMethod,
mainDirectoryPath
);
res.set("Access-Control-Allow-Origin", "*");
res.set("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
res.set("Access-Control-Allow-Credentials", "true");
res.set("Content-Type", "application/json");
res.send(JSON.stringify(dependencyOrder));
});
app.get("/jsnavigator/postman", (req, res) => {
const lastExecutedFile = logReader("./Logs.txt", dependencyOrder);
const executedPath = {
executed: findExecutedPath(lastExecutedFile, dependencyOrder).reverse(),
};
res.set("Access-Control-Allow-Origin", "*");
res.set("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
res.set("Access-Control-Allow-Credentials", "true");
res.set("Content-Type", "application/json");
res.send(JSON.stringify(executedPath));
});
app.listen(8585, (err) => {
if (err) console.log(err);
console.log("server listening on port 8585");
});