1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# DGate v2 Configuration
# Compatible with https://dgate.io/docs/getting-started/dgate-server
version: v1
log_level: ${LOG_LEVEL:-info}
log_json: false
debug: true
tags:
# Storage configuration
storage:
type: file
dir: .dgate/data/
# Proxy server configuration
proxy:
port: ${PORT:-80}
host: 0.0.0.0
console_log_level: info
# Global headers added to all responses
global_headers:
X-Powered-By: DGate-v2
# HTTP client transport settings
client_transport:
disable_private_ips: false
# Initial resources loaded at startup
init_resources:
namespaces:
- name: "default"
tags:
- name: "url_shortener"
tags:
services:
- name: "httpbin"
namespace: "default"
urls:
- "https://httpbin.org"
request_timeout_ms: 30000
collections:
- name: "short_links"
namespace: "url_shortener"
visibility: private
modules:
# Health check - using inline raw JavaScript (payloadRaw)
- name: "health-check"
namespace: "default"
moduleType: javascript
payloadRaw: |
function requestHandler(ctx) {
ctx.json({
status: 'healthy',
timestamp: new Date().toISOString(),
version: 'v0.1.0'
});
}
# Echo handler - using inline raw JavaScript (payloadRaw)
- name: "echo-handler"
namespace: "default"
moduleType: javascript
payloadRaw: |
function requestHandler(ctx) {
ctx.json({
method: ctx.request.method,
path: ctx.request.path,
query: ctx.request.query,
headers: ctx.request.headers,
body: ctx.request.body,
params: ctx.params
});
}
# URL Shortener - using file reference (payloadFile)
- name: "url-shortener"
namespace: "url_shortener"
moduleType: javascript
payloadFile: "module_examples/url_shortener.js"
routes:
# Default namespace routes
- name: "httpbin-route"
namespace: "default"
paths:
methods:
service: "httpbin"
strip_path: true
- name: "echo-route"
namespace: "default"
paths:
methods:
modules:
- name: "health-route"
namespace: "default"
paths:
methods:
modules:
# URL Shortener routes
- name: "url-shortener-create"
namespace: "url_shortener"
paths:
methods:
modules:
- name: "url-shortener-redirect"
namespace: "url_shortener"
paths:
methods:
modules:
domains:
# Route url_shortener.localhost to the url_shortener namespace
- name: "url-shortener-domain"
namespace: "url_shortener"
patterns:
# Admin API configuration
admin:
port: 9080
host: 0.0.0.0
allow_list:
- "127.0.0.1/8"
- "::1"
# Cluster configuration (Raft consensus)
# Uncomment to enable cluster mode for high availability
#
# cluster:
# enabled: true
#
# # Unique node ID (must be different for each node in the cluster)
# node_id: 1
#
# # Address this node advertises to other nodes
# advertise_addr: "192.168.1.10:9090"
#
# # Port for Raft inter-node communication
# raft_port: 9090
#
# # Bootstrap as single-node cluster (use for first node only)
# bootstrap: true
#
# # Static list of initial cluster members (alternative to discovery)
# # initial_members:
# # - id: 1
# # addr: "192.168.1.10:9090"
# # - id: 2
# # addr: "192.168.1.11:9090"
# # - id: 3
# # addr: "192.168.1.12:9090"
#
# # DNS-based discovery (useful for Kubernetes headless services)
# # discovery:
# # type: dns
# # dns_name: "dgate-headless.default.svc.cluster.local"
# # dns_port: 9090
# # refresh_interval_secs: 30
#
# # Raft tuning parameters
# heartbeat_interval_ms: 500
# election_timeout_min_ms: 1500
# election_timeout_max_ms: 3000
# snapshot_threshold: 1000