-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
149 lines (125 loc) · 5.38 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var http = require('http');
var fs = require('fs');
var path = require('path');
var formidable = require('formidable');
var excelExport = require('./Backend/runProcess');
http.createServer(function (request, response) {
console.log('request starting...');
var filePath = '.' + request.url;
if (filePath == './') {
filePath = './index.html';
} else if (filePath == './ExportToExcel') {
var form = new formidable.IncomingForm();
form.parse(request);
form.on('fileBegin', function (name, file) {
file.path = __dirname + '/ImportXML/' + file.name;
});
form.on('file', function (name, file) {
console.log('Uploaded ' + file.name);
});
filePath = './index.html';
} else if (filePath == './options') {
var type = "";
var header = [];
var localPath = "";
var sheetName = "";
var write_Path = "";
const { headers, method, url } = request;
let body = [];
request.on('error', (err) => {
console.error(err);
}).on('data', (chunk) => {
body.push(chunk);
}).on('end', () => {
body = Buffer.concat(body).toString();
var responseData = JSON.parse(body)
if (responseData.oparation == "findEndPoints") {
header = ["Proxy Service Path", "EndPoints"];
sheetName = "EndPoints";
type = responseData.serviceType;
localPath = responseData.localProjectPath;
write_Path = process.env.USERPROFILE+"/Desktop/"+responseData.projectName+"/EndPoints_" + type + ".xlsx";
} else if (responseData.oparation == "writeFiletoXlsxForReferances") {
header = ["Proxy Service Path","Type Id", "References", "Reference Resource Type", "# BS invoked", "# PX invoked"];
localPath = "";
sheetName = "Referances";
type = "";
write_Path = process.env.USERPROFILE+"/Desktop/"+responseData.projectName+"/References.xlsx";
} else if (responseData.oparation == "writeFiletoXlsxForPath") {
header = ["Proxy Service Path"];
localPath = "";
sheetName = "Resources";
type = "";
write_Path = process.env.USERPROFILE+"/Desktop/"+responseData.projectName+"/Resources.xlsx";
} else if (responseData.oparation == "compareProject") {
header = ["File Path","Is there"];
localPath = responseData.localProjectPath;
sheetName = "application Tree";
type = "";
write_Path = process.env.USERPROFILE+"/Desktop/"+responseData.projectName+"/project_tree.xlsx";
}
var options = {
projectName: responseData.projectName,
oparation: responseData.oparation,
readPath: "./ImportXML/ExportInfo",
writePath: write_Path,
localProjectPath: localPath,
repateStatus: false,
headers: header,
sheetName: sheetName,
serviceType: type,
oracleVersion: responseData.oVersion
}
console.log(options);
var response = excelExport.runProcess(options);
console.log("One Iteration | Status:", response);
});
}
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js':
contentType = 'text/javascript';
break;
case '.css':
contentType = 'text/css';
break;
case '.json':
contentType = 'application/json';
break;
case '.png':
contentType = 'image/png';
break;
case '.jpg':
contentType = 'image/jpg';
break;
case '.wav':
contentType = 'audio/wav';
break;
}
fs.readFile(filePath, function (error, content) {
if (error) {
if (error.code == 'ENOENT') {
fs.readFile('./404.html', function (error, content) {
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
});
}
else {
response.writeHead(500);
response.end('Sorry, check with the site admin for error: ' + error.code + ' ..\n');
response.end();
}
}
else {
response.setHeader('Access-Control-Allow-Origin', 'http://127.0.0.1:8125');
response.setHeader('Access-Control-Allow-Origin', 'http://127.0.0.1:8126');
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
response.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
response.setHeader('Access-Control-Allow-Credentials', true);
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
}
});
}).listen(8125);
console.log('Server running at http://127.0.0.1:8125/');