froggy-docs 1.0.9 → 1.1.0

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 CHANGED
Binary file
@@ -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
  }
@@ -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
- Future<void> startServer({int port = defaultPort}) async {
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,51 @@ 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
- // The "Try It Out" button will call your actual API endpoints
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
+ final headers = <String, String>{};
158
+
159
+ request.headers.forEach((key, value) {
160
+ if (key.toLowerCase() != 'host') {
161
+ headers[key] = value;
162
+ }
163
+ });
164
+
165
+ String? body;
166
+ if (method != 'GET' && method != 'HEAD') {
167
+ body = await request.readAsString();
168
+ }
169
+
170
+ final proxyResponse = await http.Request(method, Uri.parse(targetUrl))
171
+ .send();
172
+
173
+ final responseBody = await proxyResponse.stream.bytesToString();
174
+
175
+ return Response(
176
+ proxyResponse.statusCode,
177
+ body: responseBody,
178
+ headers: {
179
+ 'Content-Type': proxyResponse.headers['content-type'] ?? 'application/json',
180
+ ..._corsHeaders,
181
+ },
182
+ );
183
+ } catch (e) {
184
+ return Response.internalServerError(
185
+ body: '{"error": "Proxy error: $e"}',
186
+ headers: {'Content-Type': 'application/json'},
187
+ );
188
+ }
189
+ });
142
190
 
143
191
  router.get('/<path|[^/]+>', (Request request, String path) async {
144
192
  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.0.9",
3
+ "version": "1.1.0",
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",
package/pubspec.yaml CHANGED
@@ -19,6 +19,7 @@ dependencies:
19
19
  watcher: ^1.2.1
20
20
  shelf: ^1.4.2
21
21
  shelf_router: ^1.1.4
22
+ http: ^1.4.0
22
23
 
23
24
  dev_dependencies:
24
25
  lints: ^6.0.0