cozsucks commited on
Commit
abed4cc
1 Parent(s): 7b2d73c

Create server.js

Browse files
Files changed (1) hide show
  1. server.js +22 -0
server.js ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const proxy = require('express-http-proxy');
3
+
4
+ const app = express();
5
+
6
+ const targetUrl = 'https://api.openai.com'; // OpenAI API endpoint
7
+
8
+ const openai_key = process.env.OPENAI_KEY
9
+
10
+ app.use('/', proxy(targetUrl, {
11
+ proxyReqOptDecorator: (proxyReqOpts, srcReq) => {
12
+ // Modify the request headers if necessary
13
+ proxyReqOpts.headers['Authorization'] = 'Bearer '+openai_key;
14
+ return proxyReqOpts;
15
+ },
16
+ }));
17
+
18
+ const port = 7860;
19
+
20
+ app.listen(port, () => {
21
+ console.log(`Reverse proxy server listening on port ${port}`);
22
+ });