Skip to content

Commit

Permalink
Improved test coverage and publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
iyifr committed Jun 6, 2024
1 parent f922262 commit 53d7707
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- publish
pull_request:
branches: publish
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

Expand Down
6 changes: 2 additions & 4 deletions bin/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ void main(List<String> 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<bool>("/25/**", (event) => true);

router.get("/:id", (event) {
print('param: ${event.params["id"]}');
return 'Hey';
return 'Hey ${event.params["id"]}';
});

router.post("/vamos", (event) async {
Expand Down
1 change: 1 addition & 0 deletions lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ resolveHandler(H4Event event, handlerResult) {
return;
}

// Another data type will be stringified by HttpResponse.write()
setEventResponseFormat(event, handlerResult);
event.writeToClient(handlerResult);
}
12 changes: 10 additions & 2 deletions lib/src/h4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/src/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Function(HttpRequest) defineEventHandler(
event.eventParams = params ?? {};

// If onRequest is defined, call it with the event.

if (onRequest != null) {
onRequest(event);
}
Expand Down

0 comments on commit 53d7707

Please sign in to comment.