joyent-portal/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');
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);
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
};