Open cat-ninja opened 1 year ago
I was able to workaround this by patching this line locally:
new Function(middlewareConfig).call({ require, app, logger: logger_1.default, allRoutes });
and using this.require
inside of my custom middleware
I am looking into a more appropriate way to handle this, but would you like to try a dynamic import?
(async () => {
this.logger.info("inside middleware");
const express = await import("express");
this.app.use(express.json({ limit: '10mb' }));
this.app.use(express.urlencoded({ limit: '10mb', extended: true }));
this.app.use("/", this.allRoutes);
})();
I don't see any errors, but I haven't validated if the middlewares are actually applied.
@shubhendumadhukar the snippet you provided works okay for me in case of importing express
. But if I do
(async () => {
const multer = await import("multer");
this.app.use(multer().any());
this.app.use("/", this.allRoutes);
})();
I get
this.app.use(multer().any());
^
TypeError: multer is not a function
at eval (eval at start (/Users/fedor/.nvm/versions/node/v20.2.0/lib/node_modules/camouflage-server/dist/index.js:176:9), <anonymous>:5:18)
with this.require
it works okay for me
(() => {
const multer = this.require('multer');
this.app.use(multer().any());
this.app.use("/", this.allRoutes);
})();
I figured it works if I do
(async () => {
const multer = (await import('multer')).default;
this.app.use(multer().any());
this.app.use("/", this.allRoutes);
})();
Describe the bug I'm trying to increase the max request body size by registering this middleware:
The server crashes with the next error: