-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (31 loc) · 1.11 KB
/
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
32
33
34
35
36
37
38
39
const fs = require("fs");
const path = require("path");
const express = require("express");
const { negotiateHandlerFactory } = require("rdf-serve");
express.static.mime.define({ "text/shex": ["shex"] });
const app = express();
app.get("/shex/*", (req, res) => {
const wildcardPath = req.params["0"];
console.log("wildcardPath", wildcardPath);
fs.readFile(`shapes/shex/${wildcardPath}.shex`, "utf8", (err, data) => {
if (err) {
res.status(404).send();
} else {
res.setHeader("Content-Type", "text/shex");
res.setHeader("Access-Control-Allow-Origin", "*");
res.status(200).send(data);
}
});
});
app.get("/trees/*", async (req, res) => {
const response = await negotiateHandlerFactory(
path.join(__dirname, "shapes")
)(req, res);
// Add the UTF8 charset to Turtle or special characters will appear incorrectly
if (response.getHeader("Content-Type") === "text/turtle") {
res.setHeader("Content-Type", "text/turtle; charset=utf-8");
}
res.setHeader("Access-Control-Allow-Origin", "*");
return response;
});
module.exports = app.listen(process.env.PORT || 8000);