Skip to content

Commit

Permalink
perf: stream bundled OpenAPI file instead of sending it wholesale (#361)
Browse files Browse the repository at this point in the history
* perf: stream bundled OpenAPI file instead of sending it wholesale

* chore: update default host URL
  • Loading branch information
kanadgupta authored Aug 26, 2021
1 parent 1fcc890 commit 8fbf131
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
// eslint-disable-next-line global-require
cli: require('../package.json').name,
host: 'https://dash.readme.io',
host: 'https://dash.readme.com',
hub: 'https://{project}.readme.io',
};
46 changes: 41 additions & 5 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"parse-link-header": "^1.0.1",
"read": "^1.0.7",
"semver": "^7.0.0",
"table-layout": "^1.0.0"
"table-layout": "^1.0.0",
"tmp-promise": "^3.0.2"
},
"devDependencies": {
"@readme/eslint-config": "^6.0.0",
Expand Down
9 changes: 8 additions & 1 deletion src/cmds/openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { getProjectVersion } = require('../lib/versionSelect');
const fetch = require('node-fetch');
const FormData = require('form-data');
const parse = require('parse-link-header');
const { file: tmpFile } = require('tmp-promise');

exports.command = 'openapi';
exports.usage = 'openapi [file] [options]';
Expand Down Expand Up @@ -117,8 +118,14 @@ exports.run = async function (opts) {
return Promise.reject(err);
});

// Create a temporary file to write the bundled spec to,
// which we will then stream into the form data body
const { path } = await tmpFile({ prefix: 'rdme-openapi-', postfix: '.json' });
await fs.writeFileSync(path, bundledSpec);
const stream = fs.createReadStream(path);

const formData = new FormData();
formData.append('spec', bundledSpec);
formData.append('spec', stream);

const options = {
headers: cleanHeaders(key, {
Expand Down

0 comments on commit 8fbf131

Please sign in to comment.