-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (54 loc) · 2.07 KB
/
index.js
File metadata and controls
67 lines (54 loc) · 2.07 KB
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
let express = require('express');
let fs = require('fs');
let path = require('path');
let app = express();
// load table/data providers
fs.readdirSync("./providers/").forEach(function(file) {
let stat;
stat = fs.statSync("./providers/" + "/" + file);
if (!stat.isDirectory() && !file.endsWith("html.js") && file.endsWith(".js"))
{
let oModule = require("./providers/"+file);
app.use("/tables/"+file.replace(".js",""),oModule);
console.log("adding provider: "+file.replace(".js",""));
}
});
// load converters
fs.readdirSync("./converters/").forEach(function(file) {
let stat;
stat = fs.statSync("./converters/" + "/" + file);
if (!stat.isDirectory() && !file.endsWith("html.js") && file.endsWith(".js"))
{
let oModule = require("./converters/"+file);
app.use("/converters/"+file.replace(".js",""),oModule);
console.log("adding converters: "+file.replace(".js",""));
}
});
// list all converters/providers
app.get('/', function (req, res) {
let sList = "Data providers: <br>";
fs.readdirSync("./providers/").forEach(function(file) {
let stat;
stat = fs.statSync("" + "./providers/" + "/" + file);
if (!stat.isDirectory() && !file.endsWith("html.js") && file.endsWith(".js"))
{
sList += "<a href='/tables/"+file.replace(".js","")+"/'>"+file.replace(".js","")+"</a><br>";
}
});
sList += "converters: <br>";
fs.readdirSync("./converters/").forEach(function(file) {
let stat;
stat = fs.statSync("" + "./converters/" + "/" + file);
if (!stat.isDirectory() && !file.endsWith("html.js") && file.endsWith(".js"))
{
sList += "<a href='./converters/"+file.replace(".js","")+"/'>"+file.replace(".js","")+"</a><br>";
}
});
res.send(sList);
});
app.get('/files/:FILE/', function (req, res) {
res.sendFile(req.params.FILE, { root: path.join(__dirname, './static-files') });
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});