1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 15:20:06 +02:00
copilot/portal-api/lib/index.js
2017-05-03 10:08:05 +01:00

57 lines
1.1 KiB
JavaScript

'use strict';
const GraphqlHapi = require('graphql-server-hapi');
const Data = require('./data');
const Graphql = require('./models/graphql');
const Pack = require('../package.json');
const Routes = require('./routes');
module.exports = function (server, options, next) {
const data = new Data(options.data);
data.connect((err) => {
if (err) {
return next(err);
}
server.bind(data);
server.register([
{
register: GraphqlHapi.graphqlHapi,
options: {
path: '/graphql',
graphqlOptions: Graphql.options(data),
route: {
cors: true
}
}
}
]);
if (process.env.NODE_ENV === 'dev') {
server.register({
register: GraphqlHapi.graphiqlHapi,
options: {
path: '/graphiql',
graphiqlOptions: Graphql.options(data),
route: {
cors: true
}
}
});
}
server.route(Routes);
next();
});
};
module.exports.attributes = {
name: Pack.name,
version: Pack.version,
once: true,
multiple: false
};