Skip to content

Commit

Permalink
fix: REST API docs not showing
Browse files Browse the repository at this point in the history
Fixes #442
  • Loading branch information
mountaindude committed May 11, 2022
1 parent e6a6557 commit bef031f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 45 deletions.
34 changes: 18 additions & 16 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,6 @@ async function build(opts = {}) {
restServer.register(require('./plugins/sensible'), { options: Object.assign({}, opts) });
restServer.register(require('./plugins/support'), { options: Object.assign({}, opts) });

// Loads all plugins defined in routes
restServer.register(require('./routes/api'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/base_conversion'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/butler_ping'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/disk_utils'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/key_value_store'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/mqtt_publish_message'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/newrelic_metric'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/scheduler'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/sense_app'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/sense_app_dump'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/sense_list_apps'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/sense_start_task'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/slack_post_message'), { options: Object.assign({}, opts) });

restServer.register(FastifySwagger, {
routePrefix: '/documentation',
swagger: {
Expand All @@ -152,9 +137,11 @@ async function build(opts = {}) {
url: 'https://github.com/ptarmiganlabs',
description: 'Butler family of tools on GitHub',
},
host: `${globals.config.get('Butler.restServerConfig.serverHost')}:${globals.config.get('Butler.restServerConfig.serverPort')}`,
schemes: ['http'],
// consumes: ['application/json'],
produces: ['application/json'],
},
host: `${globals.config.get('Butler.restServerConfig.serverHost')}:${globals.config.get('Butler.restServerConfig.serverPort')}`,
uiConfig: {
deepLinking: true,
operationsSorter: 'alpha', // can also be 'alpha' or a function
Expand All @@ -163,6 +150,21 @@ async function build(opts = {}) {
exposeRoute: true,
});

// Loads all plugins defined in routes
restServer.register(require('./routes/api'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/base_conversion'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/butler_ping'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/disk_utils'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/key_value_store'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/mqtt_publish_message'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/newrelic_metric'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/scheduler'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/sense_app'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/sense_app_dump'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/sense_list_apps'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/sense_start_task'), { options: Object.assign({}, opts) });
restServer.register(require('./routes/slack_post_message'), { options: Object.assign({}, opts) });

// ---------------------------------------------------
// Configure X-HTTP-Method-Override handling
proxyRestServer.register(FastifyReplyFrom, {
Expand Down
46 changes: 17 additions & 29 deletions src/butler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ const start = async () => {
globals.logger.debug(`REST server host: ${globals.config.get('Butler.restServerConfig.serverHost')}`);
globals.logger.debug(`REST server port: ${globals.config.get('Butler.restServerConfig.serverPort')}`);

restServer.listen(
globals.config.get('Butler.restServerConfig.backgroundServerPort'),
'localhost',
(err, address) => {
if (err) {
globals.logger.error(`MAIN: Background REST server could not listen on ${address}`);
globals.logger.error(`MAIN: ${err}`);
restServer.log.error(err);
process.exit(1);
}
globals.logger.verbose(`MAIN: Background REST server listening on ${address}`);

restServer.ready((err2) => {
if (err2) throw err;
restServer.swagger();
});
restServer.listen(globals.config.get('Butler.restServerConfig.backgroundServerPort'), 'localhost', (err, address) => {
if (err) {
globals.logger.error(`MAIN: Background REST server could not listen on ${address}`);
globals.logger.error(`MAIN: ${err}`);
restServer.log.error(err);
process.exit(1);
}
);
globals.logger.verbose(`MAIN: Background REST server listening on ${address}`);

restServer.ready((err2) => {
if (err2) throw err;
restServer.swagger();
});
});

proxyRestServer.listen(
globals.config.get('Butler.restServerConfig.serverPort'),
Expand All @@ -60,26 +56,18 @@ const start = async () => {

// Start Docker healthcheck REST server on port set in config file
if (
(globals.config.has('Butler.dockerHealthCheck.enabled') &&
globals.config.get('Butler.dockerHealthCheck.enabled') === true) ||
(globals.config.has('Butler.dockerHealthCheck.enable') &&
globals.config.get('Butler.dockerHealthCheck.enable') === true)
(globals.config.has('Butler.dockerHealthCheck.enabled') && globals.config.get('Butler.dockerHealthCheck.enabled') === true) ||
(globals.config.has('Butler.dockerHealthCheck.enable') && globals.config.get('Butler.dockerHealthCheck.enable') === true)
) {
try {
globals.logger.verbose('MAIN: Starting Docker healthcheck server...');

await dockerHealthCheckServer.listen(globals.config.get('Butler.dockerHealthCheck.port'));

globals.logger.info(
`MAIN: Started Docker healthcheck server on port ${globals.config.get(
'Butler.dockerHealthCheck.port'
)}.`
);
globals.logger.info(`MAIN: Started Docker healthcheck server on port ${globals.config.get('Butler.dockerHealthCheck.port')}.`);
} catch (err) {
globals.logger.error(
`MAIN: Error while starting Docker healthcheck server on port ${globals.config.get(
'Butler.dockerHealthCheck.port'
)}.`
`MAIN: Error while starting Docker healthcheck server on port ${globals.config.get('Butler.dockerHealthCheck.port')}.`
);
dockerHealthCheckServer.log.error(err);
process.exit(1);
Expand Down

0 comments on commit bef031f

Please sign in to comment.