This repository was archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (43 loc) · 1.31 KB
/
server.js
File metadata and controls
53 lines (43 loc) · 1.31 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
import express from "express"
import nunjucks from "nunjucks"
import config from "./config"
import { enrichHandler, indexingHandler } from "./src/enrich"
import schemes from "./data/schemes"
const app = express()
app.set("json spaces", 2)
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*")
next()
})
app.use(express.static("./static"))
app.use("/dist/", express.static("dist"))
app.set("views", "../views")
app.set("view engine", "html")
nunjucks.configure("views", { express: app, autoescape: true })
const pages = {
"": config.title,
voc: "Vokabulare",
indexing: "Sacherschließung",
mappings: "Mappings",
api: "API",
}
for (let [path, title] of Object.entries(pages)) {
app.get(`/${path}`, (req, res) => res.render(path || "index", { pages, title, path, config }) )
}
app.get("/api/config", (req, res) => res.json(config))
app.get("/api/voc", (req, res) => res.json(schemes))
app.get("/api/indexing", indexingHandler)
app.get("/api/enrich", enrichHandler)
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
const error = {
statusCode: err.statusCode || 500,
message: err.message,
}
console.error(err)
res.status(error.statusCode)
res.json(error)
})
app.listen(config.port, () => {
console.log(`Now listening on port ${config.port}`)
})