For example, the backend provides such an interfacehttp://wx.lxjjz.cn/do?g=api&m=hd&a=works-list
.
Then my front-end ajax should be written like this
$.ajax({
url:'/do?g=api&m=hd&a=works-list',
success:(data)=>{
console.log(data)
}
})
Is this the correct way to write node routing? How should I write some interface parameters? How does node send a request to the backend interface and then pass the data to the template?
app.get( '/do', function( req, res ){
res.render( 'index.ejs' ); //请求跳转到 index.ejs文件
})
Node serves as the middle layer, which means that node serves as both a server and a client. As a client, it initiates an HTTP request to the back-end interface, and as a server, it obtains the back-end data and renders it or directly returns JSON
In addition, before and after separation, Node must obtain the back-end data, formulate a reasonable routing address, return JSON data, and use AJAX to request the node address at the browser level
Browser (ajax) -> Middle layer (node) -> SERVER backend
Node carries the tasks of page rendering and routing, and the SERVER backend carries the data processing tasks