2016-10-22 22:35:32 +00:00
|
|
|
var hapi = require('hapi');
|
2016-10-22 22:39:23 +00:00
|
|
|
var joi = require('joi');
|
2016-10-20 21:58:56 +00:00
|
|
|
var cfg = require('../cfg/websrv.json');
|
2016-10-22 22:35:32 +00:00
|
|
|
|
|
|
|
const server = new hapi.Server();
|
2016-10-20 21:58:56 +00:00
|
|
|
|
|
|
|
var templates = {};
|
|
|
|
var lib;
|
|
|
|
|
|
|
|
module.exports = Websrv;
|
|
|
|
function Websrv(tlib) {
|
|
|
|
this.lib = lib = tlib;
|
|
|
|
|
2016-10-22 22:35:32 +00:00
|
|
|
server.connection({
|
2016-10-22 22:47:22 +00:00
|
|
|
port: cfg.port+1
|
2016-10-22 22:35:32 +00:00
|
|
|
});
|
2016-10-20 21:58:56 +00:00
|
|
|
|
2016-10-22 22:35:32 +00:00
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/',
|
|
|
|
handler: function (req, reply) {
|
|
|
|
return reply('hello world');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/{ID}',
|
|
|
|
handler: function (req, reply) {
|
|
|
|
return reply('ID: ' + encodeURIComponent(req.params.ID));
|
|
|
|
},
|
|
|
|
config: {
|
|
|
|
validate: {
|
|
|
|
params: {
|
2016-10-22 22:39:23 +00:00
|
|
|
ID: joi.number()
|
2016-10-20 21:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-22 22:35:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
server.start((err) => {
|
|
|
|
if(err)
|
|
|
|
throw err;
|
2016-10-22 22:43:24 +00:00
|
|
|
console.log('Server running at:', server.info.uri);
|
2016-10-22 22:35:32 +00:00
|
|
|
});
|
|
|
|
}
|