-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
47 lines (38 loc) · 1.24 KB
/
server.ts
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
/* eslint-disable no-console */
import express from 'express'
import conditional from 'express-conditional-middleware'
import knossos from '@hydrofoil/knossos'
import compression from 'compression'
import injectMeta from '@wikibus/ograph-inject-middleware'
import fs from 'fs'
import path from 'path'
import ParsingClient from 'sparql-http-client/ParsingClient.js'
import { fileURLToPath } from 'url'
import * as Sentry from '@wikibus/sentry'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const sparqlEndpoint = {
endpointUrl: `${process.env.SPARQL_ENDPOINT}`,
user: process.env.SPARQL_USER,
password: process.env.SPARQL_PASSWORD,
}
const app = express()
Sentry.setup(app)
app.enable('trust proxy')
app.use(compression())
const root = './apps/www/dist'
app.use('/app', express.static(root))
const appIndex = path.resolve(__dirname, root, 'index.html')
app.use('/app', conditional(
req => !!req.accepts('html'),
injectMeta({
index: fs.readFileSync(appIndex).toString(),
client: new ParsingClient(sparqlEndpoint),
}),
))
// TODO: knossos should name-export or become ESM
const apis = (knossos as any).default({
name: 'wikibus',
...sparqlEndpoint,
})
app.use('/', apis)
app.listen(parseInt(process.env.PORT!, 10) || 8080)