Skip to content

Commit

Permalink
Enable Dart 2.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Stargator committed Aug 8, 2018
1 parent 3931190 commit 2b9e875
Show file tree
Hide file tree
Showing 9 changed files with 962 additions and 954 deletions.
9 changes: 5 additions & 4 deletions bin/web_server.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "dart:io";
import "dart:async";
import "package:dart2_constant/io.dart" as io;
import "package:web_server/web_server.dart" as webServer;

/**
Expand Down Expand Up @@ -48,15 +49,15 @@ Future<Null> main(final List<String> args) async {

// Handle errors
localWebServer.httpServerHandler
..onErrorDocument(HttpStatus.NOT_FOUND, (final HttpRequest httpRequest) {
..onErrorDocument(io.HttpStatus.notFound, (final HttpRequest httpRequest) {
// Use the helper method from this WebServer package
webServer.HttpServerRequestHandler.sendPageNotFoundResponse(httpRequest,
'<h1>${HttpStatus.NOT_FOUND} - Page not found</h1>');
'<h1>${io.HttpStatus.notFound} - Page not found</h1>');
})
..onErrorDocument(HttpStatus.INTERNAL_SERVER_ERROR, (final HttpRequest httpRequest) {
..onErrorDocument(io.HttpStatus.internalServerError, (final HttpRequest httpRequest) {
// Use the helper method from this WebServer package
webServer.HttpServerRequestHandler.sendInternalServerErrorResponse(httpRequest,
'<h1>${HttpStatus.INTERNAL_SERVER_ERROR} - Internal Server Error</h1>');
'<h1>${io.HttpStatus.internalServerError} - Internal Server Error</h1>');
});
}

Expand Down
1 change: 1 addition & 0 deletions example/virtual_directory.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "dart:io";
import "dart:async";
import "package:dart2_constant/io.dart" as io;
import "package:web_server/web_server.dart" as webServer;

Future<Null> main() async {
Expand Down
7 changes: 4 additions & 3 deletions example/web_server_misc.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "dart:io";
import "package:dart2_constant/io.dart" as io;
import "package:web_server/web_server.dart";

void main() {
Expand Down Expand Up @@ -47,17 +48,17 @@ void main() {
})

// Add a custom function for handling the request in case of the error code supplied as the parameter.
..onErrorDocument(HttpStatus.NOT_FOUND, (final HttpRequest httpRequest) {
..onErrorDocument(io.HttpStatus.notFound, (final HttpRequest httpRequest) {
httpRequest.response
..statusCode = HttpStatus.NOT_FOUND
..statusCode = io.HttpStatus.notFound
..headers.contentType = new ContentType('text', 'html', charset: 'utf-8')
..write('<h1>404 Error accessing: ${httpRequest.requestedUri.path}</h1>')
..close();
});

// Attach WebSocket command listeners and base events
localWebServer.webSocketServerHandler
..on[0].listen((final WebSocketRequestPayload requestPayload) { /*...*/ })
..on[0].listen((final dynamic requestPayload) { /*...*/ })
..onConnectionOpen.listen((final WebSocketConnectionData connectionData) { /*...*/ })
..onConnectionError.listen((final WebSocket webSocket) { /*...*/ })
..onConnectionClose.listen((final WebSocket webSocket) { /*...*/ });
Expand Down
4 changes: 2 additions & 2 deletions lib/src/web_server/api_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ApiResponse {
* Calls [toJson], then processes it through [JSON.encode()] before returning.
*/
String toJsonEncoded() {
return JSON.encode(this.toJson());
return convert.json.encode(this.toJson());
}
}

Expand Down Expand Up @@ -112,6 +112,6 @@ class ApiErrorResponse {
}

String toJsonEncoded() {
return JSON.encode(this.toJson());
return convert.json.encode(this.toJson());
}
}
Loading

0 comments on commit 2b9e875

Please sign in to comment.