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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2018-09-02 vulcanjs 包类型
2018-09-02 vulcanjs schemas&& collections
2018-09-02 vulcanjs 核心架构概念
2018-09-02 vulcanjs 开源工具方便快速开发react graphql meteor 应用
2014-09-02 转微软最新的Web服务器Katana发布了版本3