Spaces:
Sleeping
Sleeping
Create Dockerfile
Browse files- Dockerfile +50 -0
Dockerfile
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from 'express';
|
| 2 |
+
import fetch from 'node-fetch';
|
| 3 |
+
|
| 4 |
+
const app = express();
|
| 5 |
+
app.use(express.raw({type: '*/*'}));
|
| 6 |
+
|
| 7 |
+
// Hello World на главной
|
| 8 |
+
app.get('/', (req, res) => {
|
| 9 |
+
res.send('Hello World');
|
| 10 |
+
});
|
| 11 |
+
|
| 12 |
+
// Прокси для всех остальных путей
|
| 13 |
+
app.all('*', async (req, res) => {
|
| 14 |
+
if (req.url === '/') return;
|
| 15 |
+
|
| 16 |
+
try {
|
| 17 |
+
const url = `https://api.groq.com${req.url}`;
|
| 18 |
+
|
| 19 |
+
// Копируем и фильтруем заголовки
|
| 20 |
+
const headers = {...req.headers};
|
| 21 |
+
delete headers['host'];
|
| 22 |
+
delete headers['content-length'];
|
| 23 |
+
|
| 24 |
+
const response = await fetch(url, {
|
| 25 |
+
method: req.method,
|
| 26 |
+
headers,
|
| 27 |
+
body: req.method !== 'GET' ? req.body : undefined
|
| 28 |
+
});
|
| 29 |
+
|
| 30 |
+
// Streaming response
|
| 31 |
+
if (response.headers.get('content-type')?.includes('text/event-stream')) {
|
| 32 |
+
res.setHeader('Content-Type', 'text/event-stream');
|
| 33 |
+
response.body.pipe(res);
|
| 34 |
+
return;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// Regular response
|
| 38 |
+
const data = await response.buffer();
|
| 39 |
+
res.status(response.status);
|
| 40 |
+
res.set('Content-Type', response.headers.get('content-type'));
|
| 41 |
+
res.send(data);
|
| 42 |
+
|
| 43 |
+
} catch (error) {
|
| 44 |
+
res.status(500).send(error.message);
|
| 45 |
+
}
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
app.listen(7860, '0.0.0.0', () => {
|
| 49 |
+
console.log('Server running on port 7860');
|
| 50 |
+
});
|