1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-01 07:30:07 +02:00
copilot/portal-api/lib/index.js

57 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-04-28 00:59:03 +03:00
'use strict';
const GraphqlHapi = require('graphql-server-hapi');
2017-05-11 23:28:32 +03:00
const PortalData = require('portal-data');
2017-04-28 00:59:03 +03:00
const Graphql = require('./models/graphql');
const Pack = require('../package.json');
const Routes = require('./routes');
module.exports = function (server, options, next) {
2017-05-11 23:28:32 +03:00
const data = new PortalData(options.data);
2017-05-02 01:28:03 +03:00
data.connect((err) => {
if (err) {
return next(err);
}
2017-04-28 00:59:03 +03:00
2017-05-02 01:28:03 +03:00
server.bind(data);
server.register([
{
register: GraphqlHapi.graphqlHapi,
options: {
path: '/graphql',
graphqlOptions: Graphql.options(data),
route: {
cors: true
}
2017-04-28 00:59:03 +03:00
}
}
2017-05-02 01:28:03 +03:00
]);
if (process.env.NODE_ENV === 'dev') {
server.register({
register: GraphqlHapi.graphiqlHapi,
options: {
path: '/graphiql',
graphiqlOptions: Graphql.options(data),
route: {
cors: true
}
2017-04-28 00:59:03 +03:00
}
2017-05-02 01:28:03 +03:00
});
}
2017-04-28 00:59:03 +03:00
2017-05-02 01:28:03 +03:00
server.route(Routes);
2017-04-28 00:59:03 +03:00
2017-05-02 01:28:03 +03:00
next();
});
2017-04-28 00:59:03 +03:00
};
module.exports.attributes = {
name: Pack.name,
version: Pack.version,
once: true,
multiple: false
};