31 lines
923 B
TypeScript
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: '请求错误' }
|
|
}
|
|
}
|
|
} |