Update Dockerfile
Browse files- Dockerfile +7 -45
Dockerfile
CHANGED
|
@@ -1,50 +1,12 @@
|
|
| 1 |
-
|
| 2 |
-
import fetch from 'node-fetch';
|
| 3 |
|
| 4 |
-
|
| 5 |
-
app.use(express.raw({type: '*/*'}));
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
res.send('Hello World');
|
| 10 |
-
});
|
| 11 |
|
| 12 |
-
|
| 13 |
-
app.all('*', async (req, res) => {
|
| 14 |
-
if (req.url === '/') return;
|
| 15 |
|
| 16 |
-
|
| 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 |
-
|
| 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 |
-
});
|
|
|
|
| 1 |
+
FROM node:18-slim
|
|
|
|
| 2 |
|
| 3 |
+
WORKDIR /app
|
|
|
|
| 4 |
|
| 5 |
+
COPY package.json ./
|
| 6 |
+
RUN npm install
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
COPY index.js ./
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
EXPOSE 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
CMD ["node", "index.js"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|