From c4243d6bd1b71d1f8bee05daf2b8a49d74f9d4f9 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Sat, 9 Sep 2023 23:26:08 +0800 Subject: [PATCH] add hosting proxy configuration --- docker/.env.example | 2 ++ packages/server/.env.example | 2 ++ packages/server/src/index.ts | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docker/.env.example b/docker/.env.example index 16b19cdcf..bee2dfbfe 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -5,6 +5,8 @@ APIKEY_PATH=/root/.flowise SECRETKEY_PATH=/root/.flowise LOG_PATH=/root/.flowise/logs +# NUMBER_OF_PROXIES= 1 + # DATABASE_TYPE=postgres # DATABASE_PORT="" # DATABASE_HOST="" diff --git a/packages/server/.env.example b/packages/server/.env.example index bedbf6381..07dbf6b64 100644 --- a/packages/server/.env.example +++ b/packages/server/.env.example @@ -5,6 +5,8 @@ PASSPHRASE=MYPASSPHRASE # Passphrase used to create encryption key # SECRETKEY_PATH=/your_api_key_path/.flowise # LOG_PATH=/your_log_path/.flowise/logs +# NUMBER_OF_PROXIES= 1 + # DATABASE_TYPE=postgres # DATABASE_PORT="" # DATABASE_HOST="" diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 7143bdc5e..8d83cb8a7 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -102,6 +102,9 @@ export class App { this.app.use(express.json({ limit: '50mb' })) this.app.use(express.urlencoded({ limit: '50mb', extended: true })) + if (process.env.NUMBER_OF_PROXIES && parseInt(process.env.NUMBER_OF_PROXIES) > 0) + this.app.set('trust proxy', parseInt(process.env.NUMBER_OF_PROXIES)) + // Allow access from * this.app.use(cors()) @@ -121,7 +124,8 @@ export class App { '/api/v1/prediction/', '/api/v1/node-icon/', '/api/v1/components-credentials-icon/', - '/api/v1/chatflows-streaming' + '/api/v1/chatflows-streaming', + '/api/v1/ip' ] this.app.use((req, res, next) => { if (req.url.includes('/api/v1/')) { @@ -132,6 +136,16 @@ export class App { const upload = multer({ dest: `${path.join(__dirname, '..', 'uploads')}/` }) + // ---------------------------------------- + // Configure number of proxies in Host Environment + // ---------------------------------------- + this.app.get('/api/v1/ip', (request, response) => { + response.send({ + ip: request.ip, + msg: 'See the IP returned in the response. If it matches your IP address (which you can get by going to http://ip.nfriedly.com/ or https://api.ipify.org/), then the number of proxies is correct and the rate limiter should now work correctly. If not, then keep increasing the number until it does.' + }) + }) + // ---------------------------------------- // Components // ----------------------------------------