File size: 1,987 Bytes
27c0254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6ef08b
 
 
27c0254
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const express = require('express');
const fs = require('fs').promises;
const path = require('path');

const app = express();
app.use(express.json());

const PORT = 6666;

// JSON processing endpoint
app.post('/api/process', async (req, res) => {
    try {
        const inputData = req.body;
        
        // Example processing - echoes input with timestamp
        const response = {
            received: inputData,
            timestamp: new Date().toISOString(),
            processed: true
        };
        
        res.json(response);
    } catch (error) {
        res.status(500).json({ error: 'Processing failed', message: error.message });
    }
});

// Image serving endpoint

/*
app.get('/api/image', async (req, res) => {
    try {
        // Create a simple test image if it doesn't exist
        const imagePath = path.join(__dirname, 'test-image.png');
        
        try {
            await fs.access(imagePath);
        } catch {
            // If image doesn't exist, create a placeholder
            const { createCanvas } = require('canvas');
            const canvas = createCanvas(200, 200);
            const ctx = canvas.getContext('2d');
            
            // Draw something simple
            ctx.fillStyle = '#3498db';
            ctx.fillRect(0, 0, 200, 200);
            
            ctx.fillStyle = '#ffffff';
            ctx.font = '20px Arial';
            ctx.fillText('Test Image', 50, 100);
            
            // Save the image
            const buffer = canvas.toBuffer('image/png');
            await fs.writeFile(imagePath, buffer);
        }
        
        // Read and send the image
        const imageBuffer = await fs.readFile(imagePath);
        res.set('Content-Type', 'image/png');
        res.send(imageBuffer);
    } catch (error) {
        res.status(500).json({ error: 'Image serving failed', message: error.message });
    }
});*/


app.listen(PORT, () => {
    console.log(`API server running on port ${PORT}`);
});