f0ckv1/src/websrv.js

45 lines
815 B
JavaScript
Raw Normal View History

2016-10-22 22:35:32 +00:00
var hapi = require('hapi');
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({
port: cfg.port
});
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: {
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
});
}