-
Notifications
You must be signed in to change notification settings - Fork 8
/
hapitest.js
54 lines (45 loc) · 1.4 KB
/
hapitest.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
const Hapi = require('hapi');
const server = new Hapi.Server();
var fs= require('fs');
var path = require('path');
server.connection({
host: 'localhost',
port: 8000
});
const getConfigFile = function (env, base_directory) {
try {
// Try to load the user's personal configuration file
return require(base_directory + '/conf.my.' + env + '.json');
} catch (e) {
// Else, read the default configuration file
return require(base_directory + '/conf.' + env + '.json');
}
};
var env = process.env.NODE_ENV;
if(!env){ env = 'test' };
var conf = getConfigFile(env, "./");
console.log('conf',conf.testshinytooth.database);
server.register(
[require('h2o2'),{ register: require('./index'), options: conf }]//This is loading couch-provider
, function (err) {
if (err) {
console.log('Failed to load h2o2');
}
server.route({
method: 'GET',
path: '/test/{docId}/{docName}',
handler: function(request, reply){
// var route;
console.log('handler test server', request.params.docId);
var name = request.params.docName;
server.methods.couchprovider.getDocument(request.params.docId)
.then(function(doc){
var uri = server.methods.couchprovider.getDocumentURIAttachment(doc, name);
reply.proxy(uri);
});
}
});
server.start(function (err) {
console.log('Server started at:'+ server.info.uri);
});
});