export chat service listen host
This commit is contained in:
parent
19f92fec09
commit
6da58473d8
48
chat.js
48
chat.js
@ -4,33 +4,37 @@ const http = require('http');
|
||||
const {once} = require("node:events");
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
let body = '';
|
||||
req.on('data', chunk => {
|
||||
body += chunk.toString(); // 将Buffer转换为字符串
|
||||
});
|
||||
try {
|
||||
let body = '';
|
||||
req.on('data', chunk => {
|
||||
body += chunk.toString(); // 将Buffer转换为字符串
|
||||
});
|
||||
|
||||
await once(req, 'end');
|
||||
await once(req, 'end');
|
||||
|
||||
let requests = JSON.parse(body);
|
||||
let requests = JSON.parse(body);
|
||||
|
||||
console.log(requests.id)
|
||||
console.log(requests.msg)
|
||||
console.log(requests.id)
|
||||
console.log(requests.msg)
|
||||
|
||||
client.steamUser.chat.sendFriendMessage(requests.id, requests.msg, (err, response) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.statusCode = 500;
|
||||
client.steamUser.chat.sendFriendMessage(requests.id, requests.msg, (err, response) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.statusCode = 500;
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.end('Internal Server Error\n');
|
||||
return;
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.end('Internal Server Error\n');
|
||||
return;
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.end('Success\n');
|
||||
})
|
||||
res.end('Success\n');
|
||||
})
|
||||
} catch (e) {
|
||||
console.error("An error occurred while processing the request: ", e);
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(3000, '127.0.0.1', () => {
|
||||
console.log('Server running at http://127.0.0.1:3000/');
|
||||
server.listen(3000, '0.0.0.0', () => {
|
||||
console.log('Server running at http://0.0.0.0:3000/');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user