@@ -3,13 +3,19 @@ import 'package:shelf/shelf.dart';
33import 'package:shelf/shelf_io.dart' as io;
44import 'package:shelf_static/shelf_static.dart' ;
55
6- void main () async {
6+ void main (List < String > arguments ) async {
77 // Check if index.html exists
8+ String staticSitePath = arguments.isNotEmpty ? arguments[0 ] : 'build/web' ;
9+
810 String indexFile = 'index.html' ;
911 final handler = const Pipeline ()
1012 .addMiddleware (logRequests ())
1113 .addMiddleware (_corsHeaders) // Add CORS headers middleware
12- .addHandler (createStaticHandler ('build/web' , defaultDocument: indexFile));
14+ .addHandler (createStaticHandler (
15+ staticSitePath,
16+ defaultDocument: indexFile,
17+ serveFilesOutsidePath: false ,
18+ ));
1319
1420 final handler2 = const Pipeline ()
1521 .addMiddleware (logRequests ())
@@ -19,7 +25,7 @@ void main() async {
1925 final server = await io.serve (handler, InternetAddress .anyIPv4, 4001 );
2026 final server2 = await io.serve (handler2, InternetAddress .anyIPv4, 4002 );
2127 print (
22- 'Serving static site at http://${server .address .host }:${server .port }/${ indexFile } ' );
28+ 'Serving static site at http://${server .address .host }:${server .port }/$indexFile ' );
2329 print (
2430 'Serving handling requests at http://${server2 .address .host }:${server2 .port }' );
2531}
0 commit comments