update
This commit is contained in:
57
frontend/server.js
Normal file
57
frontend/server.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const axios = require('axios');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const API_URL = process.env.API_URL || 'http://localhost:5001';
|
||||
|
||||
// Serve static files
|
||||
app.use(express.static('public'));
|
||||
app.use(express.json());
|
||||
|
||||
// API proxy
|
||||
app.get('/api/news', async (req, res) => {
|
||||
try {
|
||||
const response = await axios.get(`${API_URL}/api/news`);
|
||||
res.json(response.data);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to fetch news' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/stats', async (req, res) => {
|
||||
try {
|
||||
const response = await axios.get(`${API_URL}/api/stats`);
|
||||
res.json(response.data);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to fetch stats' });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/subscribe', async (req, res) => {
|
||||
try {
|
||||
const response = await axios.post(`${API_URL}/api/subscribe`, req.body);
|
||||
res.json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json(
|
||||
error.response?.data || { error: 'Failed to subscribe' }
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/unsubscribe', async (req, res) => {
|
||||
try {
|
||||
const response = await axios.post(`${API_URL}/api/unsubscribe`, req.body);
|
||||
res.json(response.data);
|
||||
} catch (error) {
|
||||
res.status(error.response?.status || 500).json(
|
||||
error.response?.data || { error: 'Failed to unsubscribe' }
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Frontend server running on http://localhost:${PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user