Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
59 lines (51 loc) · 1.5 KB
/
Copy pathserver.js
File metadata and controls
59 lines (51 loc) · 1.5 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
"use strict";
var server = module.exports = { };
var jsonApi = require("../.");
var fs = require("fs");
var path = require("path");
jsonApi.setConfig({
swagger: {
title: "Example JSON:API Server",
version: "0.1.1",
description: "This is the API description block that shows up in the swagger.json",
contact: {
name: "API Contact",
url: "docs.hapi.holidayextras.com"
},
license: {
name: "MIT",
url: "http://opensource.org/licenses/MIT"
}
},
protocol: "http",
hostname: "localhost",
port: 16006,
base: "rest",
meta: {
description: "This block shows up in the root node of every payload"
}
});
jsonApi.authenticate(function(request, callback) {
// If a "blockMe" header is provided, block access.
if (request.headers.blockme) return callback("Fail");
// If a "blockMe" cookie is provided, block access.
if (request.cookies.blockMe) return callback("Fail");
return callback();
});
fs.readdirSync(path.join(__dirname, "/resources")).filter(function(filename) {
return /^[a-z].*\.js$/.test(filename);
}).map(function(filename) {
return path.join(__dirname, "/resources/", filename);
}).forEach(require);
jsonApi.onUncaughtException(function(request, error) {
var errorDetails = error.stack.split("\n");
console.error(JSON.stringify({
request: request,
error: errorDetails.shift(),
stack: errorDetails
}));
});
jsonApi.start();
server.start = jsonApi.start;
server.close = jsonApi.close;