Skip to content

Commit

Permalink
Fix/body parser (#96)
Browse files Browse the repository at this point in the history
* fix: set custom file upload size

* docs: updated swagger

* fix: default value for setting

* fix: body-parser dependency

Co-authored-by: noctera <[email protected]>
  • Loading branch information
noctera and noctera authored Dec 18, 2022
1 parent 0f8f4d3 commit c04105d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Controllers/InfoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const sendInfo = catchAsync(async (_req, res) => {
version: getVersion(),
locked: config.service.invite_code,
commitRef: gitDescribe === undefined ? (gitDescribe = await getGitDescribe()) : gitDescribe,
max_file_upload: config.server.max_file_upload,
email_confirm: {
enabled: config.service.email_confirm,
level: config.service.email_confirm_level,
Expand Down
1 change: 1 addition & 0 deletions app/config/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const configSchema = Joi.object({
.forbidden()
.messages({ 'any.unknown': 'The `sever.registration_locked` option is moved to `service.invite_code`' }),
cors: Joi.alternatives().try(Joi.boolean(), Joi.keyArray()).default(false),
max_file_upload: Joi.string().default('1mb'),
}).required(),

database: Joi.object({
Expand Down
3 changes: 3 additions & 0 deletions docs/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,9 @@
"commitRef": {
"type": "string"
},
"max_file_upload": {
"type": "string"
},
"email_confirm": {
"type": "object",
"properties": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"dependencies": {
"bcrypt": "^5.0.0",
"body-parser": "^1.20.1",
"chalk": "^4.1.0",
"cli-highlight": "^2.1.11",
"commander": "^8.3.0",
Expand Down
5 changes: 5 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const http = require('http');
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const chalk = require('chalk');
const httpStatus = require('http-status');
const eta = require('eta');
Expand Down Expand Up @@ -46,6 +47,10 @@ const createServer = async (extraConfig) => {
next();
});

// set body parser limit
server.app.use(bodyParser.json({ limit: config.server.max_file_upload }));
server.app.use(bodyParser.urlencoded({ extended: true, limit: config.server.max_file_upload }));

// logging middleware
server.app.use(LoggingMiddleware);

Expand Down
1 change: 1 addition & 0 deletions vocascan.config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
jwt_secret: '',
salt_rounds: 10,
cors: ['https://web.example1.com', 'https://web.example2.com'],
max_file_upload: '10mb',
},

database: {
Expand Down

0 comments on commit c04105d

Please sign in to comment.