Hello All,
Recently, I started building a function (with the help of AI) in one of the NodeJS projects to allow users to send an email to a unique+dedicated email address with attachments. These emails are forwarded by the receiving email service provider to a dedicated webhook (API endpoint in Wappler app). Once the data is received, the attachments are saved on the app server.
To achieve this, AI suggested setting up an Express App that contained the complete logic of this function (limits on allowed file extensions, upto 3 files, verifying sender information with the saved DB records, saving attachments, writing the final information to a database etc.).
The data is received from the external provider in a JSON format. The maximum payload that is allowed for JSON data per API call in Wappler is 100KB, which is insufficient to cover file sizes upto 5-6MB. So, to get it working, I had to add a limit: '90MB'
parameter in the server.js
file. A high limit value allows any JSON bloat (between 3-5 times the original file size) when converting a PDF or Image to JSON.
I also needed to change the index.js file to register the express app and make it available on the PORT 3000.
I have come across some discussion around increasing the payload size in the server.js. However, the server.js as well as index.js files gets overwritten during each update. Are there any alternative solutions
- to increase the payload limits without modifying the server.js file
- to register the express app without altering the index.js file
I have been thinking about a likely solution that can work even with all Wappler updates. But I don't know whether these are workable solutions within Wappler's ecosystem.
1. server.js - add a section to allow optional values. See my comments next to the param limit: '90mb'
app.use(express.urlencoded({ extended: true }));
app.use(express.json({
verify: (req, res, buf) => {
req.rawBody = buf.toString()
},
limit: '90mb' - permanently add the param `limit` and allow value from {{env.JSON_LIMIT}}}
}));
- it can be a permanent part of the server.js file and will only allow reading of ENV vars from the config.js file
- add a new section
App Limits
or a more appropriate header underServer Connect Settings
- add options here such as json payload limit, urlencoded payload limit, any other param options that may need to be modified in the server.js - if ENV values are available, then these limits apply, other standard limits apply
- index.js - I don't think there is any alternative other than to ignore this file during any wappler update after the initial creation of this file. This is the modified file to register webhook logic in the express app.
// Require the Wappler server logic (Express app)
const server = require('./lib/server');
// Require and register the webhook route logic
const emailWebhook = require('./webhook-server/email-webhook-server');
// Register the webhook endpoint on the main Express app
emailWebhook.register(server.app); // Assumes server exports { app, start }
// Start the main app on port 3000
server.start(3000);
I would love to hear from other users how they have overcome the issues outlined in my post.
I undertand that this requirement may apply only for a limited number of users at this stage. However, as the use of AI becomes more prevalent, users may need to make necessary adjustments in these two files to add advanced functionalities.