-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 849 Bytes
/
index.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
var express = require("express");
var fs = require("fs");
var app = express();
function loadJsonFromFile(jsonPath, req, res) {
fs.readFile(jsonPath, function (err, data) {
if (err) {
res.end(err.message);
} else {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(data.toString());
}
});
}
app.use(express.static(__dirname));
app.get("/", function (req, res) {
res.render("index.html");
});
app.get("/packages", function (req, res) {
loadJsonFromFile("./dist/resources/data/packages.json", req, res);
});
app.get("/package/583d8ad8fdef23aa6e000037", function (req, res) {
loadJsonFromFile("./dist/resources/data/583d8ad8fdef23aa6e000037.json", req, res);
});
app.listen(8080, function () {
console.log("Services listening on port 8080");
});