joyent-portal/bundle/src/instances.js

65 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-04-06 17:53:44 +03:00
require('../.env.js');
2018-03-29 16:43:30 +03:00
const Main = require('apr-main');
const CloudApiGql = require('cloudapi-gql');
2018-04-06 17:53:44 +03:00
const Graphi = require('graphi');
2018-03-29 16:43:30 +03:00
const Url = require('url');
2018-05-07 15:33:08 +03:00
2018-03-29 16:43:30 +03:00
const Server = require('./server');
2018-05-07 15:33:08 +03:00
const Ui = require('my-joy-instances');
2018-03-29 16:43:30 +03:00
const {
PORT = 4002,
BASE_URL = `http://0.0.0.0:${PORT}`,
PREFIX = 'instances',
DC_NAME,
SDC_URL,
SDC_KEY_PATH,
SDC_ACCOUNT,
SDC_KEY_ID
} = process.env;
const dcName = DC_NAME || Url.parse(SDC_URL).host.split('.')[0];
const keyPath = SDC_KEY_PATH;
const keyId = `/${SDC_ACCOUNT}/keys/${SDC_KEY_ID}`;
const apiBaseUrl = SDC_URL;
Main(async () => {
const server = await Server({
PORT,
BASE_URL
});
2018-05-07 15:33:08 +03:00
await server.register([
2018-04-06 17:53:44 +03:00
{
plugin: Graphi,
options: {
graphqlPath: '/graphql',
graphiqlPath: '/graphiql',
authStrategy: 'sso'
},
routes: {
prefix: `/${PREFIX}`
}
},
2018-05-07 15:33:08 +03:00
{
plugin: CloudApiGql,
options: {
authStrategy: 'sso',
keyPath,
keyId,
apiBaseUrl,
dcName
},
routes: {
prefix: `/${PREFIX}`
}
2018-03-29 16:43:30 +03:00
},
2018-05-07 15:33:08 +03:00
{
plugin: Ui
2018-03-29 16:43:30 +03:00
}
2018-05-07 15:33:08 +03:00
]);
2018-03-29 16:43:30 +03:00
await server.start();
});