haproxy 2.0 dataplaneapi rest api 转为graphql
haproxy 2.0 dataplaneapi rest api 是比较全的,以下是一个简单的集成graphql,通过swagger-to-graphql
转换为graphql api 方便使用
环境准备
- 项目准备
yarn init -y
yarn add express express-graphql graphql swagger-to-graphql
- 获取haproxy 2.0 dataplaneapi rest api swagger 定义
curl -s -X GET --user admin:dalong -H "Content-Type: application/json" http://localhost:5555/v1/specification > api.json
- 代码
const express = require('express');
const app = express();
const graphqlHTTP = require('express-graphql');
const graphQLSchema = require('swagger-to-graphql');
# 使用basic auth 输入配置好的用户以及密码
const proxyUrl = 'http://admin:dalong@localhost:5555/v1/';
const pathToSwaggerSchema = './api.json';
const customHeaders = {
// Authorization: 'Basic YWRkOmJhc2ljQXV0aA=='
};
graphQLSchema(pathToSwaggerSchema, proxyUrl, customHeaders)
.then(schema => {
app.use(
'/graphql',
graphqlHTTP(() => {
return {
schema,
graphiql: true,
};
}),
);
app.listen(3009, 'localhost', () => {
console.info('http://localhost:3009/graphql');
});
})
.catch(e => {
console.log(e);
});
- package.json 文件
{
"name": "haproxy-dataplaneapi2graphql",
"version": "1.0.0",
"main": "app.js",
"license": "MIT",
"dependencies": {
"express": "^4.17.1",
"express-graphql": "^0.9.0",
"graphql": "^14.5.4",
"swagger-to-graphql": "^2.1.0"
},
"scripts": {
"app": "node app.js"
}
}
启动&&效果
- 预备
首先需要有自己的haproxy 2.0 环境,同时配置了dataplaneapi,可以参考 https://github.com/rongfengliang/haproxy2.0-prometheus - 启动
yarn app
- 效果
- 查询效果
说明
以上是一个简单的集成,通过graphql 的查询api,我们可以方便的操作haproxy
参考资料
https://github.com/yarax/swagger-to-graphql
https://www.npmjs.com/package/swagger-to-graphql
https://github.com/rongfengliang/haproxy2.0-prometheus
https://www.haproxy.com/documentation/hapee/1-9r1/configuration/dataplaneapi/
https://github.com/rongfengliang/haproxy-dataplaneapi2graphql/tree/master
haproxy 2.0 dataplaneapi rest api 转为graphql的更多相关文章
- haproxy 2.0 dataplaneapi rest api 转为graphql docker 镜像
为了方便直接使用haproxy dataplaneapi graphql 格式的查询,制作了一个简单的docker 镜像 基于dotenv 进行配置管理,可以直接通过环境变量传入参数,处理不同hapr ...
- haproxy 2.0 dataplaneapi rest api 几个方便的问题排查接口
在使用haproxy 2.0 dataplaneapi的时候,刚开始的时候我们可能需要进行调试,保证我们的配置在我们的系统环境中 是可以使用的,以下是自己在当前学习中为了排查问题会使用的几个api 创 ...
- haproxy 2.0 dataplaneapi rest api 试用
我们可以基于haproxy 提供的dataplaneapi 动态进行haproxy 配置的修改,增强haproxy的可编程能力,以下是一个简单 的测试,基于docker-compose运行 环境准备 ...
- haproxy 2.0 dataplaneapi docker 镜像
为了方便测试dataplaneapi 基于官方的docker镜像,制作了一个简单的包含dataplaneapi 的镜像 下载dataplaneapi https://github.com/haprox ...
- haproxy 2.0 dataplaneapi 类似的工具haproxyadmin
haproxyadmin 是一个python 的pip 包,提供了类似dataplaneapi 的功能,使用上也比较简单,同时提供的方法也比较全 使用的技术与dataplaneapi 基本类似,也是一 ...
- haproxy2.0 dataplaneapi 简单说明
haproxy2.0 支持基于dataplaneapi 的haproxy 动态配置修改以及服务生效,早期大家为了动态 可以会基于dsn 的服务发现模式,基于confd 结合consul 动态生成配置并 ...
- HAProxy 2.0 and Beyond
转自:https://www.haproxy.com/blog/haproxy-2-0-and-beyond/ 关于haproxy 2.0 的新特性说明 HAProxy Technologies i ...
- 使用haproxy 2.0 prometheus metrics 监控系统状态
haproxy 2.0 已经发布一段时间了,提供内部直接暴露的prometheus metrics 很方便 ,可以快速的监控系统的状态 以下是一个简单的demo 环境准备 docker-compose ...
- ElasticSearch 5.0.1 java API操作
今天来说下使用ES 5.0.1的API来进行编码. 开始之前,简单说下5.0.1跟之前的几个变化.之前的ES自身是不支持delete-by-query的,也就是通过查询来删除,可以达到批量的效果,是因 ...
随机推荐
- Prometheus 安装部署
Prometheus 安装部署 安装版本:prometheus-2.6.1 百度云下载:https://pan.baidu.com/s/1w16lQZKw8PCHqlRuSK2i7A 提取码:lw1q ...
- MarkDown添加图片的三种方式【华为云技术分享】
Markdown插图片有三种方法,各种Markdown编辑器的插图方式也都包含在这三种方法之内. 插图最基础的格式就是:  grid-auto-rows ...
- QT Graphics-View图元组使用
通过把一个item作为另一个item的孩子,你可以得到item组的大多数本质特性:这些items会一起移动,所有变换会从父到子传递.QGraphicsItem也可以为它的孩子处理所有的事件,这样就允许 ...
- vm-install 模版创建虚拟机
主要用到的信息有:模版id和存储id 通过存储名字 # xe vm-install template=[template_uuid] new-name-label="name" s ...
- spring boot 的request.getServletContext().getRealPath路径获取问题
默认情况下springboot中request.getServletContext().getRealPath 返回的是一个临时文件夹的地址 通过查看源代码 位置在 org.springframewo ...