File size: 1,069 Bytes
abed4cc
 
 
a02cf2a
f7eb0d4
7d9059f
 
f7eb0d4
 
7d9059f
 
 
 
 
 
f7eb0d4
abed4cc
 
f7eb0d4
abed4cc
 
 
f7eb0d4
abed4cc
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const express = require('express');
const proxy = require('express-http-proxy');
const app = express();
const targetUrl = 'https://generativelanguage.googleapis.com';

app.use(express.json()); // добавляем middleware для парсинга JSON body

app.use('/', (req, res, next) => {
  console.log(`Request to: ${req.url}`); // Выводим URL запроса в консоль
  console.log(`Request method: ${req.method}`); // Выводим метод запроса
  console.log(`Request headers: ${JSON.stringify(req.headers)}`); // Выводим headers
  if (req.method !== 'GET') {
    console.log(`Request body: ${JSON.stringify(req.body)}`); // Выводим body, если он есть
  }
  next();
}, proxy(targetUrl, {
  proxyReqOptDecorator: (proxyReqOpts, srcReq) => {
    // Modify the request headers if necessary
    // proxyReqOpts.headers['Authorization'] = 'Bearer ' + openai_key;
    return proxyReqOpts;
  },
}));

const port = 7860;
app.listen(port, () => {
  console.log(`Reverse proxy server listening on port ${port}`);
});