| import express from 'express'; |
| import { createProxyMiddleware } from 'http-proxy-middleware'; |
| import { fileURLToPath } from 'url'; |
| import { dirname, join } from 'path'; |
|
|
| const __filename = fileURLToPath(import.meta.url); |
| const __dirname = dirname(__filename); |
|
|
| const app = express(); |
| const PORT = 7860; |
| const DIST_DIR = join(__dirname, 'dist'); |
|
|
| |
| app.use('/api/anthropic', createProxyMiddleware({ |
| target: 'https://api.anthropic.com', |
| changeOrigin: true, |
| pathRewrite: { '^/api/anthropic': '' }, |
| onProxyReq: (proxyReq, req) => { |
| |
| proxyReq.setHeader('x-api-key', process.env.ANTHROPIC_API_KEY); |
| proxyReq.setHeader('anthropic-version', '2023-06-01'); |
| proxyReq.setHeader('anthropic-beta', 'mcp-client-2025-04-04'); |
| }, |
| onError: (err, req, res) => { |
| console.error('Proxy error:', err); |
| res.status(502).json({ error: 'Proxy error to Anthropic' }); |
| } |
| })); |
|
|
| |
| app.get('/healthz', (req, res) => res.send('ok')); |
|
|
| |
| app.use(express.static(DIST_DIR, { index: false })); |
|
|
| |
| app.get('*', (req, res) => { |
| res.sendFile(join(DIST_DIR, 'index.html')); |
| }); |
|
|
| app.listen(PORT, '0.0.0.0', () => { |
| console.log(`Scribin' server running on port ${PORT}`); |
| }); |