Skip to content

Commit 9fd149c

Browse files
Fix ws dependencies
1 parent 2968eae commit 9fd149c

3 files changed

Lines changed: 2 additions & 103 deletions

File tree

packages/dart_node_ws/pubspec.lock

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ packages:
102102
path: "../dart_node_coverage"
103103
relative: true
104104
source: path
105-
version: "0.1.0"
106-
dart_node_express:
107-
dependency: "direct main"
108-
description:
109-
path: "../dart_node_express"
110-
relative: true
111-
source: path
112105
version: "0.9.0-beta"
113106
file:
114107
dependency: transitive

packages/dart_node_ws/pubspec.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ dependencies:
1010
austerity: ^1.3.0
1111
dart_node_core:
1212
path: ../dart_node_core
13-
dart_node_express:
14-
path: ../dart_node_express
1513
nadz: ^0.0.7-beta
1614

1715
dev_dependencies:
Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
/// Test server for WebSocket and Express integration tests.
1+
/// Test server for WebSocket tests (no Express dependency).
22
library;
33

44
import 'dart:js_interop';
55
import 'dart:js_interop_unsafe';
66

77
import 'package:dart_node_core/dart_node_core.dart';
8-
import 'package:dart_node_express/dart_node_express.dart';
98
import 'package:dart_node_ws/dart_node_ws.dart';
10-
import 'package:nadz/nadz.dart';
11-
12-
/// Port for HTTP server
13-
const httpPort = 3456;
149

1510
/// Port for WebSocket server
1611
const wsPort = 3457;
1712

1813
void main() {
19-
final wsServer = _startWebSocketServer();
20-
_startHttpServer(wsServer);
14+
_startWebSocketServer();
2115
}
2216

2317
WebSocketServer _startWebSocketServer() {
@@ -110,89 +104,3 @@ Map<String, Object?>? _parseJson(String jsonStr) {
110104
_ => null,
111105
};
112106
}
113-
114-
/// JSON body parser middleware
115-
JSFunction _jsonParser() {
116-
final expressModule = switch (requireModule('express')) {
117-
final JSObject o => o,
118-
_ => throw StateError('Express module not found'),
119-
};
120-
final jsonFn = switch (expressModule['json']) {
121-
final JSFunction f => f,
122-
_ => throw StateError('Express json function not found'),
123-
};
124-
return switch (jsonFn.callAsFunction()) {
125-
final JSFunction f => f,
126-
_ => throw StateError('Failed to create JSON parser'),
127-
};
128-
}
129-
130-
void _startHttpServer(WebSocketServer wsServer) {
131-
express()
132-
..use(_jsonParser())
133-
..get(
134-
'/health',
135-
handler((req, res) {
136-
res.jsonMap({'status': 'ok', 'wsPort': wsPort});
137-
}),
138-
)
139-
..get(
140-
'/echo/:message',
141-
handler((req, res) {
142-
final message = req.params['message'].toString();
143-
res.jsonMap({'echo': message});
144-
}),
145-
)
146-
..post(
147-
'/json',
148-
handler((req, res) {
149-
final body = req.body;
150-
res.jsonMap({'received': body.dartify(), 'success': true});
151-
}),
152-
)
153-
..get(
154-
'/error',
155-
asyncHandler((req, res) async {
156-
await Future<void>.value();
157-
throw const NotFoundError('Test error');
158-
}),
159-
)
160-
..get(
161-
'/status/:code',
162-
handler((req, res) {
163-
final code = int.tryParse(req.params['code'].toString()) ?? 200;
164-
res
165-
..status(code)
166-
..jsonMap({'statusCode': code});
167-
}),
168-
)
169-
..postWithMiddleware('/validated', [
170-
validateBody(_testSchema),
171-
handler((req, res) {
172-
switch (getValidatedBody<TestUserData>(req)) {
173-
case Error(:final error):
174-
res
175-
..status(400)
176-
..jsonMap({'error': error});
177-
case Success(:final value):
178-
res.jsonMap({'name': value.name, 'age': value.age});
179-
}
180-
}),
181-
])
182-
..use(errorHandler())
183-
..listen(
184-
httpPort,
185-
(() {
186-
consoleLog('HTTP server running on http://localhost:$httpPort');
187-
}).toJS,
188-
);
189-
}
190-
191-
/// Test user data type
192-
typedef TestUserData = ({String name, int age});
193-
194-
/// Test validation schema
195-
final _testSchema = schema<TestUserData>({
196-
'name': string().minLength(1).maxLength(100),
197-
'age': int_().min(0).max(150),
198-
}, (map) => (name: map['name']! as String, age: map['age']! as int));

0 commit comments

Comments
 (0)