Something went wrong. Try again.
Web client for TLE Community.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112import express from 'express';import _ from 'lodash';import { fileURLToPath } from 'url';import { dirname } from 'path';import Routes from './src/routes.js';
const __dirname = dirname(fileURLToPath(import.meta.url));const root = `${__dirname}/public`;
const app = express();const port = 3005;
//// Middleware to enable CORS//app.use((req, res, next) => { res.setHeader('Access-Control-Allow-Origin', req.get('origin') || ''); res.setHeader('Access-Control-Allow-Headers', 'content-type,x-requested-with,authorization'); next();});
app.use(express.json());
app.get('/', (req, res) => { res.send('Hello World');});
app.get('/announcement', (req, res) => { res.sendFile('announcement.html', { root });});
app.get('/changes.txt', (req, res) => { res.sendFile('changes.txt', { root });});
app.get('/captcha.png', (req, res) => { res.sendFile('captcha.png', { root });});
app.get('/email_attachment.png', (req, res) => { res.sendFile('email_attachment.png', { root });});
app.get('/server_overviewon', (req, res) => { res.sendFile('server_overviewon', { root });});
app.post('/:module', (req, res) => { const { module } = req.params; const method = req.body?.method || ''; const params = req.body?.params || '';
console.log(`${_.capitalize(module)}->${method} was called`, params);
const result = Routes[module]?.[method]?.(req, res);
if (result) { return res.json({ jsonrpc: '2.0', id: 1, result, }); }
const message = Boolean(module) && Boolean(method) ? `Call to stubbed endpoint ${_.capitalize(module)}->${method} not implemented yet.` : 'Invalid request.';
console.error(message);
return res.status(500).json({ jsonrpc: '2.0', id: 1, error: { message, data: null }, });});
app.post('/v2/:module/:method', (req, res) => { const { module, method } = req.params; const params = req.body;
console.log(`[v2]: ${_.capitalize(module)}->${method} was called`, params);
const result = Routes[module]?.[method]?.(req, res);
if (result) { return res.json({ jsonrpc: '2.0', id: 1, result, }); }
const message = Boolean(module) && Boolean(method) ? `Call to stubbed endpoint ${_.capitalize(module)}->${method} not implemented yet.` : 'Invalid request.';
console.error(message);
return res.status(500).json({ jsonrpc: '2.0', id: 1, error: { message, data: null }, });});
app.listen(port, () => { console.log(`TLE Community Stub Server listening on port ${port} ✅`);});