forked from MurmurationsNetwork/MurmurationsLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (28 loc) · 1.02 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
import express from 'express'
import path from 'path'
import serveIndex from 'serve-index'
import { fileURLToPath } from 'url'
import { createSchemasResponse } from './api/schemas.js'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const app = express()
const port = 8080
// static files
app.use('/countries', express.static(path.join(__dirname, '/countries')))
app.use('/fields', express.static(path.join(__dirname, '/fields')), serveIndex(path.join(__dirname, '/fields'), {'icons': true}))
app.use('/schemas', express.static(path.join(__dirname, '/schemas')), serveIndex(path.join(__dirname, '/schemas'), {'icons': true}))
app.use('/', express.static(path.join(__dirname, '/')))
app.get('/api/schemas', (req, res) => {
createSchemasResponse(req.hostname).then(json => {
res.type('json')
res.send(json)
}).catch(err => {
res.type('json')
res.send(err.message);
})
})
app.get('*', function(req, res){
res.status(404)
res.send('Page not found')
});
app.listen(port)