-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
78 lines (54 loc) · 1.33 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import "babel-polyfill"
import 'dotenv/config'
import express from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import db from './db'
import schema from './graphql'
import chalk from 'chalk'
import imageRoute from './images'
import multer from 'multer'
import {authMiddleware} from './auth'
import {
graphqlExpress,
graphiqlExpress,
} from 'apollo-server-express'
import iiif, {info} from './iiif'
import miaEndpoints from './miaEndpoints'
console.log(`
Starting Server:
env: ${process.env.NODE_ENV},
database: ${process.env.DATABASE}
`)
const upload = multer()
const server = express()
let port = process.env.PORT || 5000
server.set('port', port)
server.use(
cors(),
bodyParser.json(),
authMiddleware,
)
server.use('/mia/:type', miaEndpoints)
server.use("/image", upload.single("file") , imageRoute)
server.use('/graphiql', graphiqlExpress({
endpointURL: '/'
}))
server.use('/iiif/:identifier/info.json', info)
server.use('/iiif/:identifier/:region/:size/:rotation/:quality.:format', iiif)
server.use('/', graphqlExpress((req, res) => {
return {
schema,
context: req
}
}))
server.listen(server.get('port'), ()=>{
console.log(`Server is running at port ${server.get('port')}`)
})
// const {
// initDb
// } = process.env
//
// if (initDb === "true") {
// initalizeDb()
// }