48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
import http from 'node:http';
|
|
|
|
const moduleId = 'license-limits-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: 'ready',
|
|
capabilities: ['licenseLimits'],
|
|
note: '具体人数和素材数上限以验证系统下发的实例授权为准',
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (req.method === 'GET' && url.pathname === '/limits') {
|
|
sendJson(res, 200, {
|
|
moduleId,
|
|
status: 'entitlement_required',
|
|
error: '此模块只提供限额能力合同,具体限额必须来自已签名的实例授权',
|
|
});
|
|
return;
|
|
}
|
|
|
|
sendJson(res, 404, { moduleId, error: '接口不存在' });
|
|
});
|
|
|
|
server.listen(port, '0.0.0.0', () => {
|
|
console.log(`${moduleId} listening on ${port}`);
|
|
});
|