Need to migrate to JSON God v2, this is a breaking change
This commit is contained in:
parent
42023ca374
commit
267b696150
3 changed files with 23 additions and 34 deletions
|
@ -7,7 +7,7 @@ import 'dart:io';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'dart:mirrors';
|
import 'dart:mirrors';
|
||||||
import 'package:body_parser/body_parser.dart';
|
import 'package:body_parser/body_parser.dart';
|
||||||
import 'package:json_god/json_god.dart';
|
import 'package:json_god/json_god.dart' as god;
|
||||||
import 'package:merge_map/merge_map.dart';
|
import 'package:merge_map/merge_map.dart';
|
||||||
import 'package:mime/mime.dart';
|
import 'package:mime/mime.dart';
|
||||||
|
|
||||||
|
@ -21,4 +21,4 @@ part 'routable.dart';
|
||||||
part 'server.dart';
|
part 'server.dart';
|
||||||
part 'service.dart';
|
part 'service.dart';
|
||||||
part 'service_hooked.dart';
|
part 'service_hooked.dart';
|
||||||
part 'services/memory.dart';
|
part 'services/memory.dart';
|
||||||
|
|
|
@ -4,8 +4,8 @@ part of angel_framework.http;
|
||||||
typedef Future<HttpServer> ServerGenerator(InternetAddress address, int port);
|
typedef Future<HttpServer> ServerGenerator(InternetAddress address, int port);
|
||||||
|
|
||||||
/// Handles an [AngelHttpException].
|
/// Handles an [AngelHttpException].
|
||||||
typedef Future AngelErrorHandler(AngelHttpException err, RequestContext req,
|
typedef Future AngelErrorHandler(
|
||||||
ResponseContext res);
|
AngelHttpException err, RequestContext req, ResponseContext res);
|
||||||
|
|
||||||
/// A function that configures an [Angel] server in some way.
|
/// A function that configures an [Angel] server in some way.
|
||||||
typedef Future AngelConfigurer(Angel app);
|
typedef Future AngelConfigurer(Angel app);
|
||||||
|
@ -38,18 +38,16 @@ class Angel extends Routable {
|
||||||
List after = [];
|
List after = [];
|
||||||
|
|
||||||
HttpServer httpServer;
|
HttpServer httpServer;
|
||||||
God god = new God();
|
|
||||||
|
|
||||||
startServer(InternetAddress address, int port) async {
|
startServer(InternetAddress address, int port) async {
|
||||||
var server =
|
var server =
|
||||||
await _serverGenerator(address ?? InternetAddress.LOOPBACK_IP_V4, port);
|
await _serverGenerator(address ?? InternetAddress.LOOPBACK_IP_V4, port);
|
||||||
this.httpServer = server;
|
this.httpServer = server;
|
||||||
|
|
||||||
server.listen((HttpRequest request) async {
|
server.listen((HttpRequest request) async {
|
||||||
String req_url = request.uri.toString().replaceAll(
|
String req_url =
|
||||||
new RegExp(r'\/+$'), '');
|
request.uri.toString().replaceAll(new RegExp(r'\/+$'), '');
|
||||||
if (req_url.isEmpty)
|
if (req_url.isEmpty) req_url = '/';
|
||||||
req_url = '/';
|
|
||||||
RequestContext req = await RequestContext.from(request, {}, this, null);
|
RequestContext req = await RequestContext.from(request, {}, this, null);
|
||||||
ResponseContext res = await ResponseContext.from(request.response, this);
|
ResponseContext res = await ResponseContext.from(request.response, this);
|
||||||
|
|
||||||
|
@ -109,8 +107,8 @@ class Angel extends Routable {
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _applyHandler(handler, RequestContext req,
|
Future<bool> _applyHandler(
|
||||||
ResponseContext res) async {
|
handler, RequestContext req, ResponseContext res) async {
|
||||||
if (handler is RequestMiddleware) {
|
if (handler is RequestMiddleware) {
|
||||||
var result = await handler(req, res);
|
var result = await handler(req, res);
|
||||||
if (result is bool)
|
if (result is bool)
|
||||||
|
@ -191,8 +189,8 @@ class Angel extends Routable {
|
||||||
if (routable is Service) {
|
if (routable is Service) {
|
||||||
routable.app = this;
|
routable.app = this;
|
||||||
}
|
}
|
||||||
super.use(
|
super.use(path, routable,
|
||||||
path, routable, hooked: hooked, middlewareNamespace: middlewareNamespace);
|
hooked: hooked, middlewareNamespace: middlewareNamespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
onError(handler) {
|
onError(handler) {
|
||||||
|
@ -205,27 +203,18 @@ class Angel extends Routable {
|
||||||
if (stackTrace != null) stderr.write(stackTrace.toString());
|
if (stackTrace != null) stderr.write(stackTrace.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
Angel
|
Angel() : super() {}
|
||||||
()
|
|
||||||
:
|
|
||||||
super() {}
|
|
||||||
|
|
||||||
/// Creates an HTTPS server.
|
/// Creates an HTTPS server.
|
||||||
/// Provide paths to a certificate chain and server key (both .pem).
|
/// Provide paths to a certificate chain and server key (both .pem).
|
||||||
/// If no password is provided, a random one will be generated upon running
|
/// If no password is provided, a random one will be generated upon running
|
||||||
/// the server.
|
/// the server.
|
||||||
Angel.secure
|
Angel.secure(String certificateChainPath, String serverKeyPath,
|
||||||
(String certificateChainPath, String
|
{String password})
|
||||||
serverKeyPath
|
: super() {
|
||||||
,
|
|
||||||
{
|
|
||||||
String password
|
|
||||||
})
|
|
||||||
: super()
|
|
||||||
{
|
|
||||||
_serverGenerator = (InternetAddress address, int port) async {
|
_serverGenerator = (InternetAddress address, int port) async {
|
||||||
var certificateChain =
|
var certificateChain =
|
||||||
Platform.script.resolve('server_chain.pem').toFilePath();
|
Platform.script.resolve('server_chain.pem').toFilePath();
|
||||||
var serverKey = Platform.script.resolve('server_key.pem').toFilePath();
|
var serverKey = Platform.script.resolve('server_key.pem').toFilePath();
|
||||||
var serverContext = new SecurityContext();
|
var serverContext = new SecurityContext();
|
||||||
serverContext.useCertificateChain(certificateChain);
|
serverContext.useCertificateChain(certificateChain);
|
||||||
|
|
12
pubspec.yaml
12
pubspec.yaml
|
@ -4,10 +4,10 @@ description: Core libraries for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_framework
|
homepage: https://github.com/angel-dart/angel_framework
|
||||||
dependencies:
|
dependencies:
|
||||||
body_parser: ^1.0.0-dev
|
body_parser: ">=1.0.0-dev <2.0.0"
|
||||||
json_god: ^1.0.0
|
json_god: ">=2.0.0-beta <3.0.0"
|
||||||
merge_map: ^1.0.0
|
merge_map: ">=1.0.0 <2.0.0"
|
||||||
mime: ^0.9.3
|
mime: ">=0.9.3 <1.0.0"
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
http: ^0.11.3
|
http: ">= 0.11.3 < 0.12.0"
|
||||||
test: ^0.12.13
|
test: ">= 0.12.13 < 0.13.0"
|
Loading…
Reference in a new issue