1.0.0
This commit is contained in:
parent
a39ee0779a
commit
d5ac07d399
5 changed files with 73 additions and 2 deletions
1
.travis.yml
Normal file
1
.travis.yml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
language: dart
|
|
@ -1,4 +1,7 @@
|
||||||
# shelf
|
# shelf
|
||||||
|
[![version 1.0.0](https://img.shields.io/badge/pub-v1.0.0-brightgreen.svg)](https://pub.dartlang.org/packages/angel_shelf)
|
||||||
|
[![build status](https://travis-ci.org/angel-dart/shelf.svg)](https://travis-ci.org/angel-dart/shelf)
|
||||||
|
|
||||||
Shelf interop with Angel. Will be deprecated by v2.0.0.
|
Shelf interop with Angel. Will be deprecated by v2.0.0.
|
||||||
|
|
||||||
By version 2 of Angel, I will migrate the server to run on top of `shelf`.
|
By version 2 of Angel, I will migrate the server to run on top of `shelf`.
|
||||||
|
@ -23,8 +26,8 @@ main() async {
|
||||||
|
|
||||||
// Re-route all other traffic to an
|
// Re-route all other traffic to an
|
||||||
// existing shelf/Redstone application.
|
// existing shelf/Redstone application.
|
||||||
app.mount('/', embedShelf(
|
app.after.add(embedShelf(
|
||||||
shelf.Pipeline()
|
new shelf.Pipeline()
|
||||||
.addMiddleware(shelf.logRequests())
|
.addMiddleware(shelf.logRequests())
|
||||||
.addHandler(_echoRequest)
|
.addHandler(_echoRequest)
|
||||||
));
|
));
|
||||||
|
|
13
lib/angel_shelf.dart
Normal file
13
lib/angel_shelf.dart
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
|
import 'package:shelf/shelf.dart' as shelf;
|
||||||
|
import 'package:shelf/shelf_io.dart' as io;
|
||||||
|
|
||||||
|
/// Simply passes an incoming request to a `shelf` handler.
|
||||||
|
RequestHandler embedShelf(shelf.Handler handler) {
|
||||||
|
return (RequestContext req, ResponseContext res) async {
|
||||||
|
res
|
||||||
|
..willCloseItself = true
|
||||||
|
..end();
|
||||||
|
io.handleRequest(req.io, handler);
|
||||||
|
};
|
||||||
|
}
|
13
pubspec.yaml
Normal file
13
pubspec.yaml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
name: angel_shelf
|
||||||
|
description: Shelf interop with Angel. Will be deprecated by v2.0.0.
|
||||||
|
version: 1.0.0
|
||||||
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
|
homepage: https://github.com/angel-dart/shelf
|
||||||
|
environment:
|
||||||
|
sdk: ">=1.19.0"
|
||||||
|
dependencies:
|
||||||
|
angel_framework: ^1.0.0-dev
|
||||||
|
shelf: ^0.6.0
|
||||||
|
dev_dependencies:
|
||||||
|
angel_test: ^1.0.0-dev
|
||||||
|
test: ^0.12.0
|
41
test/all_test.dart
Normal file
41
test/all_test.dart
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
|
import 'package:angel_shelf/angel_shelf.dart';
|
||||||
|
import 'package:angel_test/angel_test.dart';
|
||||||
|
import 'package:shelf/shelf.dart' as shelf;
|
||||||
|
import 'package:shelf/shelf_io.dart' as io;
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
main() async {
|
||||||
|
Angel app;
|
||||||
|
TestClient client;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
var handler = new shelf.Pipeline()
|
||||||
|
.addMiddleware(shelf.logRequests())
|
||||||
|
.addHandler(_echoRequest);
|
||||||
|
|
||||||
|
app = new Angel();
|
||||||
|
app.get('/angel', 'Angel');
|
||||||
|
app.after.add(embedShelf(handler));
|
||||||
|
|
||||||
|
client = await connectTo(app);
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() => client.close());
|
||||||
|
|
||||||
|
test('expose angel side', () async {
|
||||||
|
var response = await client.get('/angel');
|
||||||
|
expect(JSON.decode(response.body), equals('Angel'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('expose shelf side', () async {
|
||||||
|
var response = await client.get('/foo');
|
||||||
|
expect(response, hasStatus(200));
|
||||||
|
expect(response.body, equals('Request for "foo"'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
shelf.Response _echoRequest(shelf.Request request) {
|
||||||
|
return new shelf.Response.ok('Request for "${request.url}"');
|
||||||
|
}
|
Loading…
Reference in a new issue