GeezerVison is showing github.com — perf: stream bundled OpenAPI file instead of sending it wholesale (#361) · readmeio/rdme@8fbf131
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | module.exports = { |
2 | 2 | // eslint-disable-next-line global-require |
3 | 3 | cli: require('../package.json').name, |
4 | | - host: 'https://dash.readme.io', |
| 4 | + host: 'https://dash.readme.com', |
5 | 5 | hub: 'https://{project}.readme.io', |
6 | 6 | }; |
Collapse file
Copy file name to clipboardExpand all lines: package-lock.json +41-5Lines changed: 41 additions & 5 deletions Collapse file
Copy file name to clipboardExpand all lines: package.json +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
51 | 51 | "parse-link-header": "^1.0.1", |
52 | 52 | "read": "^1.0.7", |
53 | 53 | "semver": "^7.0.0", |
54 | | - "table-layout": "^1.0.0" |
| 54 | + "table-layout": "^1.0.0", |
| 55 | + "tmp-promise": "^3.0.2" |
55 | 56 | }, |
56 | 57 | "devDependencies": { |
57 | 58 | "@readme/eslint-config": "^6.0.0", |
|
Collapse file
Copy file name to clipboardExpand all lines: src/cmds/openapi.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ const { getProjectVersion } = require('../lib/versionSelect'); |
10 | 10 | const fetch = require('node-fetch'); |
11 | 11 | const FormData = require('form-data'); |
12 | 12 | const parse = require('parse-link-header'); |
| 13 | +const { file: tmpFile } = require('tmp-promise'); |
13 | 14 |
|
14 | 15 | exports.command = 'openapi'; |
15 | 16 | exports.usage = 'openapi [file] [options]'; |
@@ -117,8 +118,14 @@ exports.run = async function (opts) { |
117 | 118 | return Promise.reject(err); |
118 | 119 | }); |
119 | 120 |
|
| 121 | + // Create a temporary file to write the bundled spec to, |
| 122 | + // which we will then stream into the form data body |
| 123 | + const { path } = await tmpFile({ prefix: 'rdme-openapi-', postfix: '.json' }); |
| 124 | + await fs.writeFileSync(path, bundledSpec); |
| 125 | + const stream = fs.createReadStream(path); |
| 126 | + |
120 | 127 | const formData = new FormData(); |
121 | | - formData.append('spec', bundledSpec); |
| 128 | + formData.append('spec', stream); |
122 | 129 |
|
123 | 130 | const options = { |
124 | 131 | headers: cleanHeaders(key, { |
|