Uh oh!
There was an error while loading. Please reload this page.
forked from holidayextras/jsonapi-server
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
Latest commit
80 lines (70 loc) · 2.01 KB
/
Copy pathserver.js
File metadata and controls
80 lines (70 loc) · 2.01 KB
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
79
80
'use strict'
constserver=module.exports={}
constjsonApi=require('../.')
constfs=require('fs')
constpath=require('path')
constdebug=require('debug')
jsonApi.setConfig({
graphiql: true,
swagger: {
title: 'Example JSON:API Server',
version: '0.1.1',
description: 'This is the API description block that shows up in the swagger.json',
termsOfService: 'http://example.com/termsOfService',
contact: {
name: 'API Contact',
email: 'apicontact@holidayextras.com',
url: 'docs.hapi.holidayextras.com'
},
license: {
name: 'MIT',
url: 'http://opensource.org/licenses/MIT'
},
security: [
{
'APIKeyHeader': []
}
],
securityDefinitions: {
APIKeyHeader: {
type: 'apiKey',
in: 'header',
name: 'X-API-Auth'
}
}
},
protocol: 'http',
hostname: 'localhost',
port: 16006,
base: 'rest',
meta: {
description: 'This block shows up in the root node of every payload'
}
})
jsonApi.authenticate((request,callback)=>{
// If a "blockMe" header is provided, block access.
if(request.headers.blockme)returncallback(newError('Fail'))
// If a "blockMe" cookie is provided, block access.
if(request.cookies.blockMe)returncallback(newError('Fail'))
returncallback()
})
fs.readdirSync(path.join(__dirname,'/resources')).filter(filename=>/^[a-z].*\.js$/.test(filename)).map(filename=>path.join(__dirname,'/resources/',filename)).forEach(require)
jsonApi.onUncaughtException((request,error)=>{
consterrorDetails=error.stack.split('\n')
console.error(JSON.stringify({
request,
error: errorDetails.shift(),
stack: errorDetails
}))
})
jsonApi.metrics.on('data',data=>{
debug('metrics')(data)
})
// If we're using the example server for the test suite,
// wait for the tests to call .start();
if(typeofdescribe==='undefined'){
jsonApi.start()
}
server.start=jsonApi.start
server.close=jsonApi.close
server.getExpressServer=jsonApi.getExpressServer