froggy-docs 1.0.9 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/froggy-docs +0 -0
- package/bin/froggy_docs.dart +11 -1
- package/lib/src/web_server.dart +56 -3
- package/package.json +1 -1
- package/pubspec.yaml +1 -0
package/bin/froggy-docs
CHANGED
|
Binary file
|
package/bin/froggy_docs.dart
CHANGED
|
@@ -14,6 +14,12 @@ void main(List<String> arguments) async {
|
|
|
14
14
|
help: 'Port for server',
|
|
15
15
|
defaultsTo: '8080',
|
|
16
16
|
);
|
|
17
|
+
parser.addOption(
|
|
18
|
+
'proxy',
|
|
19
|
+
abbr: 'x',
|
|
20
|
+
help: 'Proxy API requests to this URL (e.g., http://localhost:3000)',
|
|
21
|
+
defaultsTo: '',
|
|
22
|
+
);
|
|
17
23
|
|
|
18
24
|
try {
|
|
19
25
|
final results = parser.parse(arguments);
|
|
@@ -24,10 +30,14 @@ void main(List<String> arguments) async {
|
|
|
24
30
|
watcher.startWatching(Directory.current.path);
|
|
25
31
|
} else if (results.command?.name == 'serve') {
|
|
26
32
|
final port = int.parse(results['port'] as String);
|
|
33
|
+
final proxyUrl = results['proxy'] as String;
|
|
27
34
|
print('🐸 Starting FroggyDocs server with live reload...');
|
|
35
|
+
if (proxyUrl.isNotEmpty) {
|
|
36
|
+
print('🔄 Proxy enabled: API requests will be forwarded to $proxyUrl');
|
|
37
|
+
}
|
|
28
38
|
|
|
29
39
|
// Start server and watcher
|
|
30
|
-
await startServer(port: port);
|
|
40
|
+
await startServer(port: port, proxyUrl: proxyUrl);
|
|
31
41
|
final watcher = WatcherEngine();
|
|
32
42
|
watcher.startWatching(Directory.current.path);
|
|
33
43
|
}
|
package/lib/src/web_server.dart
CHANGED
|
@@ -5,10 +5,15 @@ import 'package:shelf/shelf.dart';
|
|
|
5
5
|
import 'package:shelf/shelf_io.dart' as shelf_io;
|
|
6
6
|
import 'package:shelf_router/shelf_router.dart';
|
|
7
7
|
import 'package:path/path.dart' as p;
|
|
8
|
+
import 'package:http/http.dart' as http;
|
|
8
9
|
|
|
9
10
|
const defaultPort = 8080;
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
String _proxyUrl = '';
|
|
13
|
+
|
|
14
|
+
Future<void> startServer({int port = defaultPort, String proxyUrl = ''}) async {
|
|
15
|
+
_proxyUrl = proxyUrl;
|
|
16
|
+
|
|
12
17
|
final handler = const Pipeline()
|
|
13
18
|
.addMiddleware(logRequests())
|
|
14
19
|
.addHandler(_router.call);
|
|
@@ -137,8 +142,56 @@ Router get _router {
|
|
|
137
142
|
// ═════════════════════════════════════════════════════════════
|
|
138
143
|
// End of Demo/Mock API
|
|
139
144
|
// In production: Remove lines 66-124 or connect to your real API
|
|
140
|
-
|
|
141
|
-
//
|
|
145
|
+
// The "Try It Out" button will call your actual API endpoints
|
|
146
|
+
// ═══════════════════════════════════════════════════════════════
|
|
147
|
+
|
|
148
|
+
// Proxy API requests to backend server
|
|
149
|
+
router.all('/api/<path.*>', (Request request, String path) async {
|
|
150
|
+
if (_proxyUrl.isEmpty) {
|
|
151
|
+
return Response.notFound('{"error": "Proxy not configured. Use --proxy http://localhost:3000"');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
final targetUrl = '$_proxyUrl/api/$path';
|
|
156
|
+
final method = request.method;
|
|
157
|
+
|
|
158
|
+
final client = http.Client();
|
|
159
|
+
http.Request req;
|
|
160
|
+
|
|
161
|
+
if (method == 'GET' || method == 'HEAD') {
|
|
162
|
+
req = http.Request(method, Uri.parse(targetUrl));
|
|
163
|
+
} else {
|
|
164
|
+
final body = await request.readAsString();
|
|
165
|
+
req = http.Request(method, Uri.parse(targetUrl));
|
|
166
|
+
if (body.isNotEmpty) {
|
|
167
|
+
req.body = body;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
request.headers.forEach((key, value) {
|
|
172
|
+
if (key.toLowerCase() != 'host') {
|
|
173
|
+
req.headers[key] = value;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
final streamedResponse = await client.send(req);
|
|
178
|
+
final responseBody = await streamedResponse.stream.bytesToString();
|
|
179
|
+
|
|
180
|
+
return Response(
|
|
181
|
+
streamedResponse.statusCode,
|
|
182
|
+
body: responseBody,
|
|
183
|
+
headers: {
|
|
184
|
+
'Content-Type': streamedResponse.headers['content-type'] ?? 'application/json',
|
|
185
|
+
..._corsHeaders,
|
|
186
|
+
},
|
|
187
|
+
);
|
|
188
|
+
} catch (e) {
|
|
189
|
+
return Response.internalServerError(
|
|
190
|
+
body: '{"error": "Proxy error: $e"}',
|
|
191
|
+
headers: {'Content-Type': 'application/json'},
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
142
195
|
|
|
143
196
|
router.get('/<path|[^/]+>', (Request request, String path) async {
|
|
144
197
|
var file = File(p.join(deployDir, path));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "froggy-docs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Auto-generate API documentation from code annotations. Works with any programming language.",
|
|
5
5
|
"author": "Kaung Mrat Thu <kaungmyatthuu.dev@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/Kaung-Myat/froggydocs",
|