HJ_Server/src/public/servertooltcp.ts
DESKTOP-15R5JU0\legu 97e070ea81 init
2023-11-17 12:02:12 +08:00

31 lines
923 B
TypeScript

import {boolean} from 'mathjs';
import request, {HttpVerb} from 'sync-request';
export class ServerToolFun {
/**
* 向server_tool服务器发起post请求
*
* @param {string} path
* @param {any} body
* @param method
* @returns { Promise<{isSucc: boolean, res?: any, err?: any}> }
*/
static async postServer(path, body, method: HttpVerb = "POST") {
console.log('gametool post: ', arguments);
let url = `http://server-tool:7456/${path}`
// let url = `http://localhost:7432/${path}` // 测试url
try {
let _option = {
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(body)
}
return await request(method, url, _option);
} catch (err) {
return { isSucc: false, err: '请求错误' }
}
}
}