File size: 1,275 Bytes
a302ca3
693011a
a302ca3
 
 
a609e99
b42a028
f663c97
f7d533f
98ae1c3
a302ca3
 
c78e699
 
 
 
 
 
 
 
 
 
6d38c7a
 
 
 
e6b820e
6d38c7a
c78e699
 
 
6d38c7a
c78e699
 
 
 
 
 
 
a302ca3
 
79bdd72
a302ca3
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const express = require('express');
const morgan = require('morgan');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();

app.use(morgan('dev'));

app.use('/hf/v1/chat/completions', createProxyMiddleware({
  target: 'http://localhost:3010/v1/chat/completions',
  changeOrigin: true
}));

app.get('/', (req, res) => {
  const htmlContent = `
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>My Static Page</title>
    </head>
    <body>
      <p> 
        Cursor To OpenAI Server <br />
        聊天来源: 自定义(兼容 OpenAI) <br />
        自定义端点(基本URL):<span id="endpoint-url"></span> <br />
        自定义API密钥:[抓取的Cursor Cookie,格式为user_...] <br />
      </p>
      <script>
        const url = new URL(window.location.href);
        const link = url.protocol + '//' + url.host + '/hf/v1';
        document.getElementById('endpoint-url').textContent = link;
      </script>
    </body>
    </html>
  `;
  res.send(htmlContent);
});

const port = process.env.HF_PORT || 7860;
app.listen(port, () => {
  console.log(`HF Proxy server is running at PORT: ${port}`);
});