- Add script to start Ollama with CORS enabled - Add proxy server option for environments without CORS support - Document CORS configuration in scripts Note: Run './scripts/start-ollama-cors.sh' or set OLLAMA_ORIGINS='*' when starting Ollama 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
39 lines
1008 B
JavaScript
39 lines
1008 B
JavaScript
import express from 'express';
|
|
import cors from 'cors';
|
|
import fetch from 'node-fetch';
|
|
|
|
const app = express();
|
|
const PORT = 3001;
|
|
|
|
// Enable CORS for all origins
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
// Proxy endpoint for Ollama API
|
|
app.post('/api/chat', async (req, res) => {
|
|
try {
|
|
const response = await fetch('http://localhost:11434/api/chat', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(req.body),
|
|
});
|
|
|
|
const data = await response.json();
|
|
res.json(data);
|
|
} catch (error) {
|
|
console.error('Proxy error:', error);
|
|
res.status(500).json({ error: 'Failed to connect to Ollama service' });
|
|
}
|
|
});
|
|
|
|
// Health check endpoint
|
|
app.get('/health', (req, res) => {
|
|
res.json({ status: 'ok', message: 'Proxy server is running' });
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`🚀 Proxy server running on http://localhost:${PORT}`);
|
|
console.log(` Proxying Ollama requests from :${PORT} to :11434`);
|
|
}); |