且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NodeJS中客户端-服务器通信的简单方法

更新时间:2021-07-01 22:40:42

经过一番研究和外界帮助,我找到了解决方案.

After some research and outside help, I've found the solution.

对于 domaintest ,定义了一条路由,该路由与我为客户端定义的路由几乎相同.好吧,对于 domaintest 路由,我必须在 router.get 之后紧接着添加下一个函数调用:

For domaintest, there was a route defined, which is almost identical to the one I defined for the client. Well, to the domaintest route, I had to add the next function call, right after router.get:

router.post('/', function(req, res) {
    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify({data: 'asd'}));
});

上面所谓的服务器代码实际上是未使用和不必要的; domaintest 充当服务器.

The so-called server code above is practically unused and unnecessary; domaintest serves as a server.