2017-05-18 21:21:33 +03:00
|
|
|
const schema = require('joyent-cp-gql-schema');
|
2017-05-27 19:35:38 +03:00
|
|
|
const graphi = require('graphi');
|
2017-05-18 21:21:33 +03:00
|
|
|
const Good = require('good');
|
|
|
|
const Hapi = require('hapi');
|
|
|
|
const resolvers = require('./resolvers');
|
|
|
|
|
|
|
|
const server = new Hapi.Server({
|
|
|
|
debug: {
|
|
|
|
log: ['error'],
|
|
|
|
request: ['error']
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const handlerError = err => {
|
|
|
|
if (err) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
server.connection({
|
2017-06-01 20:28:40 +03:00
|
|
|
port: 3000,
|
|
|
|
routes: {
|
|
|
|
cors: true
|
|
|
|
}
|
2017-05-18 21:21:33 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
server.register(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
register: Good,
|
|
|
|
options: {
|
|
|
|
reporters: {
|
|
|
|
console: [
|
|
|
|
{
|
|
|
|
module: 'good-squeeze',
|
|
|
|
name: 'Squeeze',
|
|
|
|
args: [{ log: '*', response: '*' }]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
module: 'good-console'
|
|
|
|
},
|
|
|
|
'stdout'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-05-27 19:35:38 +03:00
|
|
|
register: graphi,
|
2017-05-18 21:21:33 +03:00
|
|
|
options: {
|
2017-06-22 12:40:53 +03:00
|
|
|
graphqlPath: '/api/graphql',
|
|
|
|
graphiqlPath: '/api/graphiql',
|
2017-05-27 19:35:38 +03:00
|
|
|
schema,
|
|
|
|
resolvers
|
2017-05-18 21:21:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
err => {
|
|
|
|
handlerError(err);
|
|
|
|
|
|
|
|
server.start(err => {
|
|
|
|
handlerError(err);
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(`server started at http://0.0.0.0:${server.info.port}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|