Hritam-Ai commited on
Commit
d9f082f
Β·
1 Parent(s): 4a6d161

Delete proxy-server.js

Browse files
Files changed (1) hide show
  1. proxy-server.js +0 -118
proxy-server.js DELETED
@@ -1,118 +0,0 @@
1
- // proxy-server.js - Simple proxy server for Anthropic API calls only
2
- const express = require('express');
3
- const cors = require('cors');
4
- const fetch = require('node-fetch');
5
- const path = require('path');
6
-
7
- const app = express();
8
- const port = 3001;
9
-
10
- // HARDCODED CREDENTIALS - Replace with your actual Anthropic API key
11
- const ANTHROPIC_API_KEY = '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';
12
-
13
- // Middleware
14
- app.use(cors()); // Allow all origins for simplicity
15
- app.use(express.json({ limit: '10mb' })); // Allow larger payloads for long markdown
16
-
17
- // Serve static files (HTML, CSS, JS) from current directory
18
- app.use(express.static('.'));
19
-
20
- // Health check endpoint
21
- app.get('/health', (req, res) => {
22
- res.json({ status: 'OK', message: 'Proxy server is running' });
23
- });
24
-
25
- // Serve the main page
26
- app.get('/', (req, res) => {
27
- res.sendFile(path.join(__dirname, 'index.html'));
28
- });
29
-
30
- // Proxy endpoint for Anthropic API
31
- app.post('/summarize', async (req, res) => {
32
- try {
33
- const { markdown } = req.body;
34
-
35
- if (!markdown) {
36
- return res.status(400).json({ error: 'Markdown content is required' });
37
- }
38
-
39
- console.log(`πŸ“ Generating summary for ${markdown.length} characters of markdown...`);
40
-
41
- // Call Anthropic API
42
- const response = await fetch('https://api.anthropic.com/v1/messages', {
43
- method: 'POST',
44
- headers: {
45
- 'Content-Type': 'application/json',
46
- 'x-api-key': ANTHROPIC_API_KEY,
47
- 'anthropic-version': '2023-06-01'
48
- },
49
- body: JSON.stringify({
50
- model: 'claude-3-sonnet-20240229',
51
- max_tokens: 1000,
52
- messages: [{
53
- role: 'user',
54
- content: `Please provide a concise summary of the following markdown content. Focus on the main points, key findings, and important information:\n\n${markdown}`
55
- }]
56
- })
57
- });
58
-
59
- if (!response.ok) {
60
- const errorText = await response.text();
61
- console.error('❌ Anthropic API Error:', response.status, errorText);
62
-
63
- if (response.status === 401) {
64
- return res.status(401).json({ error: 'Invalid Anthropic API key - check your server configuration' });
65
- } else if (response.status === 429) {
66
- return res.status(429).json({ error: 'Rate limit exceeded - please try again later' });
67
- } else if (response.status >= 500) {
68
- return res.status(500).json({ error: 'Anthropic API server error - please try again later' });
69
- } else {
70
- return res.status(response.status).json({
71
- error: `Anthropic API error: ${response.status} ${response.statusText}`
72
- });
73
- }
74
- }
75
-
76
- const data = await response.json();
77
- const summary = data.content[0].text;
78
-
79
- console.log('βœ… Summary generated successfully');
80
-
81
- res.json({
82
- success: true,
83
- summary: summary
84
- });
85
-
86
- } catch (error) {
87
- console.error('❌ Proxy server error:', error);
88
-
89
- if (error.name === 'TypeError' && error.message.includes('fetch')) {
90
- res.status(503).json({ error: 'Unable to connect to Anthropic API' });
91
- } else {
92
- res.status(500).json({
93
- error: 'Internal server error',
94
- details: error.message
95
- });
96
- }
97
- }
98
- });
99
-
100
- // Error handling middleware
101
- app.use((error, req, res, next) => {
102
- console.error('❌ Server error:', error);
103
- res.status(500).json({
104
- error: 'Internal server error',
105
- details: error.message
106
- });
107
- });
108
-
109
- // Start server
110
- app.listen(port, () => {
111
- console.log('πŸš€ ========================================');
112
- console.log(`βœ… Proxy server running at http://localhost:${port}`);
113
- console.log('🌐 Open your browser and go to: http://localhost:3001');
114
- console.log('πŸ“ Make sure to update your Anthropic API key in this file');
115
- console.log('πŸš€ ========================================');
116
- });
117
-
118
- module.exports = app;