haproxy 2.0 dataplaneapi rest api 是比較全的,如下是一個簡單的集成graphql,經過swagger-to-graphql
轉換爲graphql api 方便使用node
yarn init -y
yarn add express express-graphql graphql swagger-to-graphql
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);
});
{
"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"
}
}
yarn app
以上是一個簡單的集成,經過graphql 的查詢api,咱們能夠方便的操做haproxygit
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/mastergithub