diff --git a/lib/launcher.js b/lib/launcher.js index 068fd334..a2471f9d 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -1,3 +1,4 @@ +const bytes = require('bytes') const childProcess = require('child_process') const { existsSync } = require('fs') const fs = require('fs/promises') @@ -294,6 +295,10 @@ class Launcher { ] } + if (this.settings?.editor?.apiMaxLength) { + settings.apiMaxLength = bytes(this.settings.editor.apiMaxLength) + } + // if licensed, add palette catalogues if (this.config.licensed) { if (this.project) { diff --git a/lib/template/template-settings.js b/lib/template/template-settings.js index cbf6ebce..06e5b664 100644 --- a/lib/template/template-settings.js +++ b/lib/template/template-settings.js @@ -178,6 +178,13 @@ const runtimeSettings = { editorTheme: { ...editorTheme } } +if (settings.apiMaxLength) { + runtimeSettings.apiMaxLength = settings.apiMaxLength + runtimeSettings.ui = { + maxHttpBufferSize: settings.apiMaxLength + } +} + if (!settings.localAuth?.enabled) { runtimeSettings.editorTheme.login = { message: 'Access the editor through the FlowFuse platform' diff --git a/package-lock.json b/package-lock.json index 2d25580c..6cf68623 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@flowfuse/nr-theme": "^1.8.0", "@inquirer/confirm": "^5.1.9", "@inquirer/select": "^4.2.0", + "bytes": "^3.1.2", "command-line-args": "^6.0.1", "command-line-usage": "^7.0.3", "express-session": "^1.18.0", @@ -1902,6 +1903,15 @@ "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/cacheable-lookup": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz", @@ -8427,6 +8437,11 @@ "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, + "bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" + }, "cacheable-lookup": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz", diff --git a/package.json b/package.json index 176abe31..7aa09950 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@flowfuse/nr-theme": "^1.8.0", "@inquirer/confirm": "^5.1.9", "@inquirer/select": "^4.2.0", + "bytes": "^3.1.2", "command-line-args": "^6.0.1", "command-line-usage": "^7.0.3", "express-session": "^1.18.0", diff --git a/test/unit/lib/template-settings_spec.js b/test/unit/lib/template-settings_spec.js index cb02280e..93e66d52 100644 --- a/test/unit/lib/template-settings_spec.js +++ b/test/unit/lib/template-settings_spec.js @@ -23,9 +23,9 @@ describe('template-settings', () => { dir: '', verbose: true } - async function generateSettingsFile (_config) { + async function generateSettingsFile (_config, _settings) { _config = Object.assign({}, config, _config) - const launcher = newLauncher({ config: _config }, null, 'PROJECTID', setup.snapshot) + const launcher = newLauncher({ config: _config }, null, 'PROJECTID', setup.snapshot, _settings || undefined) await launcher.writeSettings() settingsFilePath = path.join(config.dir, 'project', 'settings.js') return settingsFilePath @@ -203,6 +203,21 @@ describe('template-settings', () => { settings.httpNodeAuth.should.have.a.property('pass', '$123456789') }) + it('should set the apiMaxLength and ui.maxHttpBufferSize option if provided', async function () { + const extraConfig = {} + const extraSettings = { + editor: { + apiMaxLength: '1mb' + } + } + const settingsFile = await generateSettingsFile(extraConfig, extraSettings) + const settings = require(settingsFile) + should.exist(settings) + settings.should.have.a.property('apiMaxLength', 1048576) + settings.should.have.a.property('ui').and.be.an.Object() + settings.ui.should.have.a.property('maxHttpBufferSize', 1048576) + }) + it('should set adminAuth.type and users array when valid localAuth options are provided and enabled', async function () { const extraConfig = { localAuth: {