Spaces:
Paused
Paused
Deploy Bot commited on
Commit ·
abbb25c
1
Parent(s): 51dd86d
Enable_Static_Hosting_And_Image_Proxy
Browse files- src/api/routes.js +34 -2
- src/main.js +1 -0
src/api/routes.js
CHANGED
|
@@ -4,9 +4,41 @@ const Product = require('../models/Product');
|
|
| 4 |
const Order = require('../models/Order');
|
| 5 |
const auth = require('./middleware');
|
| 6 |
|
| 7 |
-
// Public Health Check
|
| 8 |
router.get('/status', (req, res) => {
|
| 9 |
-
res.json({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
});
|
| 11 |
|
| 12 |
// --- PROTECTED ROUTES ---
|
|
|
|
| 4 |
const Order = require('../models/Order');
|
| 5 |
const auth = require('./middleware');
|
| 6 |
|
| 7 |
+
// Public Health Check & Config
|
| 8 |
router.get('/status', (req, res) => {
|
| 9 |
+
res.json({
|
| 10 |
+
status: 'ok',
|
| 11 |
+
bot: 'active',
|
| 12 |
+
time: new Date(),
|
| 13 |
+
apk_url: `${req.protocol}://${req.get('host')}/public/app.apk` // Dynamic APK Link
|
| 14 |
+
});
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
// --- IMAGE PROXY (To show Telegram images in App) ---
|
| 18 |
+
const axios = require('axios');
|
| 19 |
+
const config = require('../../config'); // Need BOT_TOKEN
|
| 20 |
+
|
| 21 |
+
router.get('/image/:fileId', async (req, res) => {
|
| 22 |
+
try {
|
| 23 |
+
const fileId = req.params.fileId;
|
| 24 |
+
// 1. Get File Path from Telegram
|
| 25 |
+
const fileRes = await axios.get(`https://api.telegram.org/bot${config.BOT_TOKEN}/getFile?file_id=${fileId}`);
|
| 26 |
+
const filePath = fileRes.data.result.file_path;
|
| 27 |
+
|
| 28 |
+
// 2. Stream File to Client
|
| 29 |
+
const imageUrl = `https://api.telegram.org/file/bot${config.BOT_TOKEN}/${filePath}`;
|
| 30 |
+
|
| 31 |
+
const response = await axios({
|
| 32 |
+
url: imageUrl,
|
| 33 |
+
method: 'GET',
|
| 34 |
+
responseType: 'stream'
|
| 35 |
+
});
|
| 36 |
+
|
| 37 |
+
response.data.pipe(res);
|
| 38 |
+
} catch (e) {
|
| 39 |
+
console.error("Image Proxy Error:", e.message);
|
| 40 |
+
res.status(404).send('Image not found');
|
| 41 |
+
}
|
| 42 |
});
|
| 43 |
|
| 44 |
// --- PROTECTED ROUTES ---
|
src/main.js
CHANGED
|
@@ -18,6 +18,7 @@ const app = express();
|
|
| 18 |
app.use(cors());
|
| 19 |
app.use(bodyParser.json());
|
| 20 |
app.use('/api', apiRoutes);
|
|
|
|
| 21 |
|
| 22 |
const PORT = process.env.PORT || 3000;
|
| 23 |
app.listen(PORT, () => {
|
|
|
|
| 18 |
app.use(cors());
|
| 19 |
app.use(bodyParser.json());
|
| 20 |
app.use('/api', apiRoutes);
|
| 21 |
+
app.use('/public', express.static(path.join(__dirname, '../public'))); // Serve Static Files (APK, etc.)
|
| 22 |
|
| 23 |
const PORT = process.env.PORT || 3000;
|
| 24 |
app.listen(PORT, () => {
|