javascript - Separate front and back, node serves as the middle layer, how should routing be written?
仅有的幸福
仅有的幸福 2017-06-29 10:09:32
0
1
1080

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文件
})
仅有的幸福
仅有的幸福

reply all(1)
黄舟

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template