-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.js
116 lines (105 loc) · 2.51 KB
/
server.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
const r2j = require("ramldt2jsonschema");
const join = require("path").join;
const fs = require("fs");
const express = require("express");
const app = express();
const ramlEndpoint = ".raml";
const schemaEndpoint = ".schema";
const indexSubDir = "api_docs"
var linkItems = [
"absence_getId",
"absence_post",
"absence_postId",
"absence_getAll",
"account_getId",
"account_post",
"account_postId",
"account_getAll",
"batch_post",
"company_getAll",
"company_getId",
"company_post",
"company_postId",
"costcentersplitting_getAll",
"integrator_getAll",
"integrator_post",
"integrator_postId",
"integrator_getId",
"integratortype_getAll",
"integratortype_getId",
"integratortype_post",
"integratortype_postId",
"contact_getId",
"contact_post",
"contact_postId",
"contact_getAll",
"contract_getId",
"contract_post",
"contract_postId",
"contract_getAll",
"contractitem_getAll",
"invoice_getId",
"invoice_getAll",
"invoiceitem_getAll",
"invoiceposition_getAll",
"project_getId",
"project_post",
"project_postId",
"project_getAll",
"portfolio_post",
"portfolio_postId",
"portfolio_getAll",
"publicholiday_getAll",
"opportunity_getAll",
"opportunity_post",
"opportunity_postId",
"opportunity_getId",
"salesorder_getAll",
"salesorder_post",
"salesorder_getId",
"salesorder_postId",
"salesorderitem_getAll",
"salesorderitem_post",
"salesorderitem_getId",
"task_post",
"task_getId",
"task_getAll",
"timereport_getId",
"timereport_post",
"timereport_postId",
"timereport_getAll",
"volumeprice_getAll"
];
// serve files from the public directory
app.use(express.static(indexSubDir));
//start the express web server listening on 3020
/*
app.listen(3020, () => {
console.log("listening on 3020");
});
*/
// serve the homepage
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
//const currentDir = process.env.LAMBDA_TASK_ROOT;
const currentDir = __dirname +'/api_docs/' ;
const main = async function () {
let filePath;
let schema;
filePath = join(currentDir, 'planmill1_5' + ramlEndpoint);
const ramlData = fs.readFileSync(filePath).toString();
linkItems.forEach(async (name) =>
{
try {
let schema = await r2j.dt2js(ramlData, name);
let schemaStr = JSON.stringify(schema, null, 2);
let jsonfilePath = join(currentDir, name+ schemaEndpoint);
fs.writeFile(jsonfilePath, schemaStr, function (err, data) {});
} catch (e) {
console.log(e);
}
})
return;
};
main();