1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 14:10:04 +02:00
copilot/portal-api/lib/index.js
2017-05-11 23:45:27 +01:00

57 lines
1.1 KiB
JavaScript

'use strict';
const GraphqlHapi = require('graphql-server-hapi');
const PortalData = require('portal-data');
const Graphql = require('./models/graphql');
const Pack = require('../package.json');
const Routes = require('./routes');
module.exports = function (server, options, next) {
const data = new PortalData(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
};