-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
42 lines (35 loc) · 998 Bytes
/
index.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
import cors from 'cors'
import path from 'path'
import hydraBox from 'hydra-box'
import express from 'express'
import dotenv from 'dotenv'
import dotenvExpand from 'dotenv-expand'
import $rdf from 'rdf-ext'
import Parser from '@rdfjs/parser-n3'
import { createReadStream } from 'fs'
dotenvExpand(dotenv.config())
const parser = new Parser({ baseIRI: process.env.BASE_URI })
async function hydraMiddleware () {
const dataset = await $rdf.dataset()
.import(parser.import(createReadStream(path.join(__dirname, 'hydra/api.ttl'))))
return hydraBox('/api', dataset,
{
contextHeader: '/context/',
}
)
}
Promise.resolve()
.then(async () => {
const app = express()
app.set('trust proxy', true)
app.use(
cors({
exposedHeaders: ['link', 'location'],
})
)
app.use(await hydraMiddleware())
app.listen(process.env.PORT, () => {
console.log(`listening on port ${process.env.PORT}`)
})
})
.catch(err => console.error(err))