-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (34 loc) · 1020 Bytes
/
server.js
File metadata and controls
38 lines (34 loc) · 1020 Bytes
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
const Hapi = require('hapi');
const Boom = require('boom');
const typeConfig = require('./src/typeConfig');
// Create a server with a host and port
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
var typeList = typeConfig.getTypeList()
for (var index in typeList) {
(function(key, typeConfig){
server.route({
method: 'GET',
path:'/'+key,
handler: function (request, reply) {
try {
var replyVal = reply(typeConfig.getFunc(key)(request.query));
return replyVal;
} catch (err) {
console.log(err)
return reply(Boom.badRequest("Bad Request!", "Invalid Parameters?"));
}
}
});
})(typeList[index], typeConfig);
}
// Start the server!
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});