const originalEmitWarning = process.emitWarning; process.emitWarning = function(warning, ...args) { if (typeof warning === 'string' && warning.includes('punycode')) { return; } return originalEmitWarning.apply(process, [warning, ...args]); }; const express = require('express'); const cors = require('cors'); const path = require('path'); const fs = require('fs'); const config = require('./config'); const text2text = require('./AIRequest/text2text'); const img2text = require('./AIRequest/img2text'); const app = express(); app.use(cors()); app.use(express.json()); app.get('/health', (req, res) => { res.json({ status: 'ok' }); }); app.post('/api/chat', async (req, res) => { try { res.json(await text2text(req.body.prompt)); } catch (error) { res.status(error.message === 'Missing prompt' ? 400 : 500).json({ success: false, error: error.message }); } }); app.post('/api/img2text', async (req, res) => { try { res.json(await img2text(req.body.prompt, req.body.imageUrl)); } catch (error) { const statusCode = error.message === 'Missing prompt' || error.message === 'Missing imageUrl' ? 400 : 500; res.status(statusCode).json({ success: false, error: error.message }); } }); const PORT = config.PORT || 8848; const HOST = process.env.HOST || '0.0.0.0'; try { fs.appendFileSync(path.join(__dirname, 'log.txt'), `[${new Date().toISOString()}] Starting server on http://${HOST}:${PORT}\n`); } catch (error) { console.error('Failed to write start log:', error); } app.listen(PORT, HOST, () => { const logMessage = `[${new Date().toISOString()}] Server running on http://${HOST}:${PORT}\n`; console.log(`Server running on http://${HOST}:${PORT}`); try { fs.appendFileSync(path.join(__dirname, 'log.txt'), logMessage); } catch (error) { console.error('Failed to write log:', error); } });