Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
fix(env): don't require ONE_ENABLE_POST_TO_MODULE_ROUTES to be set (#738
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Matthew-Mallimo committed May 5, 2022
1 parent 0a52c85 commit e7becf0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
14 changes: 5 additions & 9 deletions __tests__/server/config/env/runTime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,11 @@ describe('runTime', () => {
expect(enablePostToModuleRoutes.defaultValue).toBe('false');
});

it('should normalize the value to lower case', () => {
expect(enablePostToModuleRoutes.normalize('Value')).toBe('value');
expect(enablePostToModuleRoutes.normalize('VALUE')).toBe('value');
it('should normalize the value to be either true or false', () => {
expect(enablePostToModuleRoutes.normalize('Value')).toBe('true');
expect(enablePostToModuleRoutes.normalize('VALUE')).toBe('true');
expect(enablePostToModuleRoutes.normalize('true')).toBe('true');
expect(enablePostToModuleRoutes.normalize('FALSE')).toBe('false');
});

it('should pass validation when value is "true" or "false"', () => {
Expand Down Expand Up @@ -493,11 +495,5 @@ describe('runTime', () => {
process.env.ONE_ENABLE_POST_TO_MODULE_ROUTES = true;
expect(() => postRequestMaxPayload.validate('20kb')).not.toThrow();
});

it('should fail validation when POSTing is not enabled', () => {
expect(() => postRequestMaxPayload.validate('20kb')).toThrowErrorMatchingInlineSnapshot(
'"ONE_ENABLE_POST_TO_MODULE_ROUTES must be \\"true\\" to configure max POST payload."'
);
});
});
});
2 changes: 1 addition & 1 deletion docs/api/server/Environment-Variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ ONE_ENABLE_POST_TO_MODULE_ROUTES=false
* ✅ Production
* ✅ Development
Maximum payload allowed in POST requests. `ONE_ENABLE_POST_TO_MODULE_ROUTES` must be true to configure this.
Maximum payload allowed in POST requests. Has no effect unless `ONE_ENABLE_POST_TO_MODULE_ROUTES` is set to true.
**Shape**
```bash
Expand Down
11 changes: 6 additions & 5 deletions src/server/config/env/runTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ const runTime = [
{
name: 'ONE_ENABLE_POST_TO_MODULE_ROUTES',
defaultValue: 'false',
normalize: (input) => input.toLowerCase(),
normalize: (input) => {
if (input.toLowerCase() === 'false') {
return 'false';
}
return `${!!input}`;
},
validate: (input) => {
if (input !== 'true' && input !== 'false') {
throw new Error(`Expected "${input}" to be "true" or "false"`);
Expand All @@ -225,10 +230,6 @@ const runTime = [
name: 'ONE_MAX_POST_REQUEST_PAYLOAD',
defaultValue: '15kb',
validate: (input) => {
if (process.env.ONE_ENABLE_POST_TO_MODULE_ROUTES !== 'true') {
throw new Error('ONE_ENABLE_POST_TO_MODULE_ROUTES must be "true" to configure max POST payload.');
}

const parsed = bytes.parse(input);

if (parsed === null) {
Expand Down

0 comments on commit e7becf0

Please sign in to comment.