Code files
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const hapi = require('hapi');
|
||||
const config = require('getconfig');
|
||||
|
||||
const init = require('./init');
|
||||
const server = new hapi.Server();
|
||||
|
||||
// init connections before registering plugins
|
||||
init.connections(server, config);
|
||||
server.ext('onPreResponse', (request, reply) => {
|
||||
var response = request.response.isBoom ?
|
||||
request.response.output :
|
||||
request.response;
|
||||
response.headers['X-DNS-Prefetch-Control'] = 'off';
|
||||
response.headers['X-DNS-Prefetch-Control'] = 'off';
|
||||
response.headers['X-Frame-Options'] = 'SAMEORIGIN';
|
||||
response.headers['X-Download-Options'] = 'noopen';
|
||||
response.headers['X-Content-Type-Options'] = 'nosniff';
|
||||
response.headers['X-XSS-Protection'] = '1; mode=block';
|
||||
reply.continue();
|
||||
});
|
||||
// register plugins
|
||||
init.registers(server);
|
||||
// loading views
|
||||
init.views(server);
|
||||
|
||||
server.start((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
server.log('info', 'Server running');
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
module.exports.connections = function(server, config) {
|
||||
require('./server').connection(server, config);
|
||||
};
|
||||
|
||||
module.exports.registers = function(server) {
|
||||
server.register([{
|
||||
register: require('./logs').register,
|
||||
options: require('./logs').options
|
||||
}, {
|
||||
register: require('nes')
|
||||
}, {
|
||||
register: require('vision')
|
||||
}, {
|
||||
register: require('inert')
|
||||
}, {
|
||||
register: require('./server').register,
|
||||
select: ['server']
|
||||
}], (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.views = function(server) {
|
||||
server.views({
|
||||
engines: {
|
||||
html: require('handlebars')
|
||||
},
|
||||
path: __dirname + '/views',
|
||||
layout: false
|
||||
//layoutPath: 'views/layout',
|
||||
//layout: 'default',
|
||||
//helpersPath: 'views/helpers',
|
||||
//partialsPath: 'views/partials'
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
// logging to console
|
||||
const logs = {
|
||||
register: require('good'),
|
||||
options: {
|
||||
ops: {
|
||||
interval: 60 * 1000
|
||||
},
|
||||
reporters: {
|
||||
console: [{
|
||||
module: 'good-console',
|
||||
args: [ { log: '*', response: '*', request: '*' } ]
|
||||
},
|
||||
'stdout'
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = logs;
|
||||
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
module.exports.connection = function(server, config) {
|
||||
server.connection({
|
||||
host: config.connections[0].server.host,
|
||||
port: config.connections[0].server.port,
|
||||
labels: config.connections[0].server.labels
|
||||
});
|
||||
};
|
||||
|
||||
// register plugin
|
||||
module.exports.register = function (server, options, next) {
|
||||
require('./routes')(server);
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports.register.attributes = {
|
||||
pkg: require('./package.json')
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "server",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(server) {
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/',
|
||||
handler: function (request, reply) {
|
||||
reply.view('index');
|
||||
}
|
||||
});
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/hello',
|
||||
handler: function (request, reply) {
|
||||
const data = {
|
||||
message1: 'Hello',
|
||||
message2: 'Paris, France'
|
||||
};
|
||||
reply.view('hello', data);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
{{message1}} from {{message2}}.
|
||||
@@ -0,0 +1 @@
|
||||
Hapi Starter Kit
|
||||
Reference in New Issue
Block a user