-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (34 loc) · 1.02 KB
/
server.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
import express from 'express'
import expressGraphQL from 'express-graphql'
import { schema } from './graphql/schema'
import yaml from 'js-yaml'
import fs from 'fs'
import jwt from 'express-jwt'
require('dotenv').load()
const server = global.server = express()
/* API */
server.use(jwt({ secret: process.env.JWT_SECRET, credentialsRequired: false}))
server.use('/graphql', expressGraphQL((request) => ({
schema: schema,
rootValue: { viewer: request.user || '' },
graphiql: true
})))
/* API docs */
server.set('view engine', 'ejs')
server.set('views', 'docs')
server.get('/docs', (req, res) => {
res.render('partials/list', {route_list: ['user', 'session']})
})
server.get('/docs/:model', (req, res) => {
let model = req.params.model
var data = {}
try {
data = yaml.safeLoad(fs.readFileSync('docs/' + model + '.yml', 'utf8'));
} catch (e) {
console.error(e);
}
res.render('partials/detail', {
model: data
})
})
server.listen(3003, () => console.info(`The server is running at http://localhost:3003`))