简体   繁体   English

使用 node.js 创建 web 服务

[英]Creating web services using node.js

So, I have 3 javascript files that do the following:所以,我有 3 个 javascript 文件,它们执行以下操作:

  • database.js: connects to the database and runs sql commands (insert, delete, update, select). database.js:连接到数据库并运行 sql 命令(插入、删除、更新、选择)。
  • mid.js: runs a method and sends the results to the database.js file to insert them into the database. mid.js:运行一个方法并将结果发送到 database.js 文件以将它们插入到数据库中。
  • main_file.js: calls the mid.js method and calls the database.js file to run sql commands. main_file.js:调用mid.js方法,调用database.js文件运行sql命令。

My question is: since main_file.js and mid.js cannot access directly to the database, I am suppose to develop some HTTP web services that will stay between my client-side javascript files (mid.js and main_file.js) and my database file (database.js).我的问题是:由于 main_file.js 和 mid.js 无法直接访问数据库,我想开发一些 HTTP web 服务,这些服务将保留在我的客户端 javascript 文件和主数据库之间文件(database.js)。 How can I create all the services and keep the above flow?如何创建所有服务并保持上述流程?

Important: some of the sql commands return a value that is used in other sql command.重要提示:一些 sql 命令返回一个在其他 sql 命令中使用的值。 For example, an insert command returns an id that is going to be used in a select command.例如,插入命令返回将在 select 命令中使用的 id。

Thank you.谢谢你。

You have two options:你有两个选择:

  1. Open database port to application server and directly connect to database.打开应用服务器的数据库端口,直接连接数据库。 There are some security measures but avoiding another abstraction layer is an advantage.有一些安全措施,但避免另一个抽象层是一个优势。

  2. At database side create the rest API which app server calls their endpoint (close to what is called web service in Windows terminology).在数据库端创建 rest API 应用服务器调用其端点(接近 ZAEAZ0 术语中的web service )。 THis abstraction level can do some extra work based on your scenario but still need to use API key for security.这个抽象级别可以根据你的场景做一些额外的工作,但仍然需要使用 API 密钥来保证安全。

After all the design decisions are based on the project.毕竟所有的设计决策都是基于项目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM