-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
91 lines (70 loc) · 1.91 KB
/
app.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
var https = require('https');
const port = process.env.PORT || 3000;
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
let repoData = {};
let repoName = '';
let copyPer = -1;
app.get("/", (req, res) => {
res.render("home");
});
app.get("/analyze", (req, res) => {
const stats = repoData.stats;
res.render("analyze", {repoData: repoData, repoName: repoName, stats: stats});
});
app.post("/analyze", (req, res) => {
const url = req.body.repoURL;
const arr = url.split("/");
repoName = arr.pop();
const options = {
hostname: 'inspect-api.herokuapp.com',
port: 443,
path: `/analysis?url=${url}`,
method: 'GET'
}
const request = https.request(options, responce => {
console.log(`statusCode: ${responce.statusCode}`)
responce.on('data', d => {
const data = JSON.parse(d);
repoData = data;
res.redirect("/analyze");
})
})
request.on('error', error => {
console.error(error)
})
request.end();
});
app.get("/compare", (req, res) => {
res.render("compare", {copyPer: copyPer});
});
app.post("/compare", (req, res) => {
const repo = {url1: req.body.repoURL1, url2: req.body.repoURL2};
const options = {
hostname: 'inspect-api.herokuapp.com',
port: 443,
path: `/compare?url1=${repo.url1}&url2=${repo.url2}`,
method: 'GET'
}
const request = https.request(options, responce => {
console.log(`statusCode: ${responce.statusCode}`)
responce.on('data', d => {
const data = JSON.parse(d);
copyPer = data;
res.redirect("/compare");
})
})
request.on('error', error => {
console.error(error)
})
request.end();
});
app.listen(port, ()=> {
console.log(`Server is running on port ${port}`);
});