search

Home  >  Q&A  >  body text

node.js - 前后端分离中避免暴露接口一般有那几种解决办法

来公司以前,项目都是前端写h5页面交给php做渲染的。
目前想提高开发效率,想前后端分离,但是要求避免暴露接口或者说避免暴露post请求里的数据和一些关键数据。
我不会php,查了几天的资料,找到的途径是用node做一层中间层,获取后端数据,并且在view层渲染直出,这种方式是不是就是大家所说的服务器渲染?
想问下有没有更好的解决办法能够避免线上环境暴露接口?
还有"后端请求接口,前端只有请求结果"这句话看到过很多次了,是什么样的设计思路

黄舟黄舟2782 days ago819

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 16:35:01

    PHP implements Data API

    Nodejs implements the business logic layer, which is actually what you call the middle layer.

    "The backend requests the interface, and the frontend only requests the results." My understanding is that the backend in this sentence is actually nodejs, and the request is PHP and other Data APIs, and finally uses the data rendering interface directly.

    Similar to the previous method of <?php echo $user_name; ?>, it is a template engine and corresponds to jade and ejs of nodejs.

    Reference:
    http://www.tangshuang.net/249...

    Supplement:
    This article by AlloyTeam is also good
    http://www.alloyteam.com/2016...

    reply
    0
  • Cancelreply