import http from 'node:http'; const moduleId = 'custom-templates-core'; const port = Number.parseInt(process.env.PORT || '8787', 10); function sendJson(res, statusCode, payload) { const body = JSON.stringify(payload); res.writeHead(statusCode, { 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': Buffer.byteLength(body), }); res.end(body); } const server = http.createServer((req, res) => { const url = new URL(req.url || '/', `http://${req.headers.host || '127.0.0.1'}`); if (req.method === 'GET' && url.pathname === '/health') { sendJson(res, 200, { moduleId, status: 'healthy' }); return; } if (req.method === 'GET' && url.pathname === '/status') { sendJson(res, 200, { moduleId, status: 'authorization_contract_ready', capabilities: ['customTemplates'], note: '模板业务仍由主应用执行;此模块先承接授权和拉包合同', }); return; } sendJson(res, 404, { moduleId, error: '接口不存在' }); }); server.listen(port, '0.0.0.0', () => { console.log(`${moduleId} listening on ${port}`); });