1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-15 07:40:07 +02:00
copilot/packages/cp-gql-mock-server/src/index.js

69 lines
1.2 KiB
JavaScript
Raw Normal View History

const schema = require('joyent-cp-gql-schema');
2017-05-27 19:35:38 +03:00
const graphi = require('graphi');
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-07-21 17:08:15 +03:00
port: process.env.PORT,
routes: {
cors: true
}
});
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,
options: {
graphqlPath: '/api/graphql',
graphiqlPath: '/api/graphiql',
2017-05-27 19:35:38 +03:00
schema,
resolvers
}
}
],
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}`);
});
}
);