strongloop/loopback-维护API的多个版本 [英] strongloop/loopback - Maintain multiple versions of API

查看:54
本文介绍了strongloop/loopback-维护API的多个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用Strongloop/loopback. 在线有一些基本说明,用于对API进行版本控制:

I am using strongloop/loopback for the first time. There is some rudimentary instruction online for versioning an API:

var p = require('../package.json');
var version = p.version.split('.').shift();
module.exports = {
  restApiRoot: '/api' + (version > 0 ? '/v' + version : ''),
  host: process.env.HOST || 'localhost',
  port: process.env.PORT || 3000
};

我看不到,是维护API多个版本的推荐方法.因此,例如,我可以同时运行旧版1.4版本和新2.0版本.有最佳做法吗?

What I don't see, is a recommended way of maintaining multiple versions of an API. So, for example, I could have a legacy 1.4 version and new 2.0 version running at the same time. Is there a best practice for doing so?

我已经接受@Overdrivr的回答,因为它在撰写本文时是准确的.但是,Github上有一个公开问题,该用户计划提交一个功能.公关希望可以在以后的迭代中添加此功能.

I have accepted @Overdrivr's answer as it is accurate at time of writing. However, there is an open issue on Github regarding this feature with a user planning to submit a PR. Hopefully this functionality will be added in a future iteration.

推荐答案

您将需要运行两台环回服务器,一台运行1.4,另一台运行2.0.例如,让一个监听端口3000,另一个监听3001.

You will need to run two loopback servers, one running 1.4 and the other 2.0. Make one listen on port 3000 and the other on 3001 for instance.

然后,您可以将nginx用作反向代理.

Then you can use nginx as reverse-proxy.

nginx将监听端口80或443(http或https),即您的客户端将访问的端口. 最后,告诉nginx将匹配/api/v1.4/的请求重新路由到服务器1.4,将匹配/api/v2/的请求重新路由到另一个服务器.

nginx will listen to port 80 or 443 (http or https), the port that your clients will reach. Finally, tell nginx to re-route requests matching /api/v1.4/ to server 1.4 and /api/v2/ to the other.

这篇关于strongloop/loopback-维护API的多个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆