Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

local/
.DS_Store
12 changes: 9 additions & 3 deletions bin/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_static/shelf_static.dart';

void main() async {
void main(List<String> arguments) async {
// Check if index.html exists
String staticSitePath = arguments.isNotEmpty ? arguments[0] : 'build/web';

String indexFile = 'index.html';
final handler = const Pipeline()
.addMiddleware(logRequests())
.addMiddleware(_corsHeaders) // Add CORS headers middleware
.addHandler(createStaticHandler('build/web', defaultDocument: indexFile));
.addHandler(createStaticHandler(
staticSitePath,
defaultDocument: indexFile,
serveFilesOutsidePath: false,
));

final handler2 = const Pipeline()
.addMiddleware(logRequests())
Expand All @@ -19,7 +25,7 @@ void main() async {
final server = await io.serve(handler, InternetAddress.anyIPv4, 4001);
final server2 = await io.serve(handler2, InternetAddress.anyIPv4, 4002);
print(
'Serving static site at http://${server.address.host}:${server.port}/${indexFile}');
'Serving static site at http://${server.address.host}:${server.port}/$indexFile');
print(
'Serving handling requests at http://${server2.address.host}:${server2.port}');
}
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ packages:
dependency: "direct dev"
description:
name: lints
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
sha256: a5e2b223cb7c9c8efdc663ef484fdd95bb243bff242ef5b13e26883547fce9a0
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "6.0.0"
logging:
dependency: transitive
description:
Expand Down Expand Up @@ -426,4 +426,4 @@ packages:
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.7.0-0 <4.0.0"
dart: ">=3.8.0-0 <4.0.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dependencies:

dev_dependencies:
dart_dev: ^4.0.0
lints: ^2.0.0
lints: ">=2.0.0 <7.0.0"
test: ^1.21.0