Skip to content

Instantly share code, notes, and snippets.

@meenie
Created April 13, 2016 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meenie/6f1815cfbad7aba387b5a00c4345c354 to your computer and use it in GitHub Desktop.
Save meenie/6f1815cfbad7aba387b5a00c4345c354 to your computer and use it in GitHub Desktop.
import {Store} from 'confidence';
import {readFileSync} from 'fs';
const criteria = {
env: process.env.NODE_ENV || 'development'
};
let store,
config;
config = {
$meta: 'Config file',
server: {
host: '0.0.0.0',
port: process.env.PORT || 3200,
options: {}
},
good: {
opsInterval: 1000,
reporters: [{
reporter: require('good-console'),
events: { log: '*' }
}]
},
postgres: {
connectionString: process.env.DATABASE_URL || 'postgres://meenie@localhost/surveys',
native: true
},
app: {
redisUrl: process.env.REDIS_URL || 'redis://localhost:6379'
}
};
store = new Store(config);
export const get = (key) => {
return store.get(key, criteria);
};
export const meta = (key) => {
return store.meta(key, criteria);
};
import {compose} from 'glue';
import * as manifest from './manifest';
compose(manifest.get('/'), {relativeTo: __dirname}, function (err, server) {
server.start(function () {
server.log('info', 'Server running at: ' + server.connections[0].info.uri);
});
});
import {Store} from 'confidence';
import * as config from './config';
const criteria = {
env: process.env.NODE_ENV || 'development'
};
let store,
manifest;
manifest = {
$meta: 'My App',
connections: [{
host: config.get('/server/host'),
port: config.get('/server/port')
}],
registrations: [
// Third Party Plugins
{
plugin: {
register: 'good',
options: config.get('/good')
}
},
{
plugin: 'nes'
},
{
plugin: {
register: 'hapi-node-postgres',
options: config.get('/postgres')
}
},
// App Plugins
{
plugin: {
register: './plugins/App',
options: config.get('/app')
}
}
]
};
store = new Store(manifest);
export const get = (key) => {
return store.get(key, criteria);
};
export const meta = (key) => {
return store.meta(key, criteria);
};
import {IHapiServer, IHapiRequest, IPluginRegister} from '../../interfaces';
import {IPluginOptions} from './interfaces';
export const register = <IPluginRegister<IPluginOptions>>function (server, options, next) {
server.route({
method: 'GET',
path: '/',
handler: function (request: IHapiRequest, reply) {
reply('Hello World');
}
});
next();
};
register.attributes = {
name: 'App',
version: '1.0.0'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment