Skip to content

Commit

Permalink
fix: API docs REST endpoint doesn't work for pre-built binaries
Browse files Browse the repository at this point in the history
Fixes #443
  • Loading branch information
mountaindude committed May 14, 2022
1 parent 6ed5a05 commit 53cf3fa
Showing 5 changed files with 53 additions and 21 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/src/butler.js",
"cwd": "${workspaceFolder}/src",
// "args": [
// "--configfile",
// "./config/production.yaml",
26 changes: 25 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
@@ -123,6 +123,27 @@ async function build(opts = {}) {
restServer.register(require('./plugins/sensible'), { options: Object.assign({}, opts) });
restServer.register(require('./plugins/support'), { options: Object.assign({}, opts) });

// let apiDocPath = '';
// if (process.pkg) {
// globals.logger.debug(`CONFIG: Running as standalone app.`);
// // apiDocPath = path.resolve(`${process.execPath}/docs/api_doc/butler-api.yaml`);
// apiDocPath = path.join(__dirname, '../docs/api_doc/butler-api.yaml');
// } else {
// globals.logger.debug(`CONFIG: Not standalone app.`);
// apiDocPath = path.join(process.cwd(), '../docs/api_doc/butler-api.yaml');
// }
// globals.logger.debug(`CONFIG: Reading static API doc file from ${apiDocPath}`);

// restServer.register(FastifySwagger, {
// mode: 'static',
// specification: {
// path: apiDocPath,
// },
// routePrefix: '/documentation',
// hideUntagged: false,
// exposeRoute: true,
// });

restServer.register(FastifySwagger, {
routePrefix: '/documentation',
swagger: {
@@ -168,7 +189,10 @@ async function build(opts = {}) {
// ---------------------------------------------------
// Configure X-HTTP-Method-Override handling
proxyRestServer.register(FastifyReplyFrom, {
base: `http://localhost:${globals.config.get('Butler.restServerConfig.backgroundServerPort')}`,
// base: `http://localhost:${globals.config.get('Butler.restServerConfig.backgroundServerPort')}`,
base: `http://${globals.config.get('Butler.restServerConfig.serverHost')}:${globals.config.get(
'Butler.restServerConfig.backgroundServerPort'
)}`,
http: true,
});

31 changes: 18 additions & 13 deletions src/butler.js
Original file line number Diff line number Diff line change
@@ -21,20 +21,25 @@ 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.listen(globals.config.get('Butler.restServerConfig.backgroundServerPort'), 'localhost', (err, address) => {
restServer.listen(
globals.config.get('Butler.restServerConfig.backgroundServerPort'),
globals.config.get('Butler.restServerConfig.serverHost'),
(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.ready((err2) => {
if (err2) throw err;
restServer.swagger();
});
}
);

proxyRestServer.listen(
globals.config.get('Butler.restServerConfig.serverPort'),
12 changes: 6 additions & 6 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -102,7 +102,9 @@
"node_modules/enigma.js/**/*.json"
],
"assets": [
"node_modules/fsevents/fsevents.node"
"node_modules/fsevents/fsevents.node",
"../docs/api_doc/butler-api.yaml",
"node_modules/@fastify/swagger"
]
}
}

0 comments on commit 53cf3fa

Please sign in to comment.