@@ -3,13 +3,19 @@ import 'package:shelf/shelf.dart';
3
3
import 'package:shelf/shelf_io.dart' as io;
4
4
import 'package:shelf_static/shelf_static.dart' ;
5
5
6
- void main () async {
6
+ void main (List < String > arguments ) async {
7
7
// Check if index.html exists
8
+ String staticSitePath = arguments.isNotEmpty ? arguments[0 ] : 'build/web' ;
9
+
8
10
String indexFile = 'index.html' ;
9
11
final handler = const Pipeline ()
10
12
.addMiddleware (logRequests ())
11
13
.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
+ ));
13
19
14
20
final handler2 = const Pipeline ()
15
21
.addMiddleware (logRequests ())
@@ -19,7 +25,7 @@ void main() async {
19
25
final server = await io.serve (handler, InternetAddress .anyIPv4, 4001 );
20
26
final server2 = await io.serve (handler2, InternetAddress .anyIPv4, 4002 );
21
27
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 ' );
23
29
print (
24
30
'Serving handling requests at http://${server2 .address .host }:${server2 .port }' );
25
31
}
0 commit comments