Skip to content

Commit 44269e7

Browse files
committed
chore: Decouple pharaoh router from instance
1 parent 7721f0e commit 44269e7

File tree

7 files changed

+8
-11
lines changed

7 files changed

+8
-11
lines changed

packages/pharaoh/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void main() async {
4242

4343
app.get('/foo', (req, res) => res.ok("bar"));
4444

45-
final guestRouter = app.router()
45+
final guestRouter = Pharaoh.router
4646
..get('/user', (req, res) => res.ok("Hello World"))
4747
..post('/post', (req, res) => res.json({"mee": "moo"}))
4848
..put('/put', (req, res) => res.json({"pookey": "reyrey"}));

packages/pharaoh/lib/src/core.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ typedef OnErrorCallback = FutureOr<Response> Function(
3030
);
3131

3232
abstract class Pharaoh implements RouterContract {
33+
static RouterContract get router => GroupRouter();
34+
3335
factory Pharaoh() => $PharaohImpl();
3436

3537
ViewEngine? get viewEngine;
@@ -40,8 +42,6 @@ abstract class Pharaoh implements RouterContract {
4042

4143
void useSpanner(Spanner spanner);
4244

43-
RouterContract router();
44-
4545
Uri get uri;
4646

4747
Pharaoh group(String path, RouterContract router);

packages/pharaoh/lib/src/core_impl.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class $PharaohImpl extends RouterContract
1919
use(bodyParser);
2020
}
2121

22-
@override
23-
RouterContract router() => GroupRouter();
24-
2522
@override
2623
Uri get uri {
2724
if (_server.address.isLoopback) {

packages/pharaoh/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: pharaoh
22
description: Minimalist web-server library for Dart
3-
version: 0.0.7+1
3+
version: 0.0.7+2
44
repository: https://github.com/codekeyz/pharaoh/tree/main/packages/pharaoh
55

66
environment:

packages/pharaoh/test/acceptance/request_handling_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void main() {
140140
(req, res) => res.json(req.params),
141141
);
142142

143-
final router = app.router()
143+
final router = Pharaoh.router
144144
..get('/', (req, res) => res.ok('Group working'))
145145
..delete('/say-hello', (req, res) => res.ok('Hello World'));
146146

packages/pharaoh/test/router/router_group_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ void main() {
66
test('should execute middlewares in group', () async {
77
final app = Pharaoh()..post('/', (req, res) => res.json(req.body));
88

9-
final adminRouter = app.router()
9+
final adminRouter = Pharaoh.router
1010
..get('/', (req, res) => res.ok('Holy Moly 🚀'))
1111
..post('/hello', (req, res) => res.json(req.body));
1212
app.group('/admin', adminRouter);

pharaoh_examples/lib/route_groups/index.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import 'package:pharaoh/pharaoh.dart';
33
final app = Pharaoh();
44

55
void main() async {
6-
final guestRouter = app.router()
6+
final guestRouter = Pharaoh.router
77
..get('/foo', (req, res) => res.ok("Hello World"))
88
..post('/bar', (req, res) => res.json({"mee": "moo"}))
99
..put('/yoo', (req, res) => res.json({"pookey": "reyrey"}));
1010

11-
final adminRouter = app.router()
11+
final adminRouter = Pharaoh.router
1212
..use(logRequests)
1313
..get('/user', (req, res) => res.json({"chima": "happy"}))
1414
..put('/hello', (req, res) => res.json({"name": "chima"}))

0 commit comments

Comments
 (0)