diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 39080c8..00c548f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,6 +4,8 @@ on: push: branches: - publish + pull_request: + branches: publish tags: - 'v[0-9]+.[0-9]+.[0-9]+*' diff --git a/bin/run.dart b/bin/run.dart index 86bd73e..2cf5b67 100644 --- a/bin/run.dart +++ b/bin/run.dart @@ -17,17 +17,15 @@ void main(List arguments) async { app.use(router); app.onRequest((event) { - print(event.path); + print(event.params); }); app.onError((error, stack, event) => print('Error occured at ${event?.path}\n$error')); - router.get("/25/**", (event) => true); router.get("/:id", (event) { - print('param: ${event.params["id"]}'); - return 'Hey'; + return 'Hey ${event.params["id"]}'; }); router.post("/vamos", (event) async { diff --git a/lib/src/event.dart b/lib/src/event.dart index 193d4ec..428fd58 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -167,6 +167,7 @@ resolveHandler(H4Event event, handlerResult) { return; } + // Another data type will be stringified by HttpResponse.write() setEventResponseFormat(event, handlerResult); event.writeToClient(handlerResult); } diff --git a/lib/src/h4.dart b/lib/src/h4.dart index 1755722..6677e44 100644 --- a/lib/src/h4.dart +++ b/lib/src/h4.dart @@ -130,6 +130,15 @@ class H4 { } _bootstrap() { + // var newStream = server?.asBroadcastStream(); + + // newStream?.listen((HttpRequest req) { + // var event = H4Event(req); + // var params = router?.getParams(req.uri.path); + // event.eventParams = params ?? {}; + // _onRequestHandler!(event); + // }); + server?.listen((HttpRequest request) { if (router == null) { print( @@ -157,8 +166,7 @@ class H4 { return { "statusCode": 404, "statusMessage": "Not found", - "message": - "Cannot ${event.method.toUpperCase()} - ${event.path}" + "message": "Cannot ${event.method.toUpperCase()} - ${event.path}" }; }, onRequest: _onRequestHandler, params: params)(request); return; diff --git a/lib/src/index.dart b/lib/src/index.dart index 7a16ab8..8215aa2 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -23,6 +23,7 @@ Function(HttpRequest) defineEventHandler( event.eventParams = params ?? {}; // If onRequest is defined, call it with the event. + if (onRequest != null) { onRequest(event); }