Bump to 2.0.0-alpha

This commit is contained in:
Tobe O 2018-08-28 10:58:28 -04:00
parent 5288b5065f
commit 2e8573cd96
12 changed files with 39 additions and 34 deletions

1
.gitignore vendored
View file

@ -63,3 +63,4 @@ packages
# Include when developing application packages. # Include when developing application packages.
pubspec.lock pubspec.lock
.dart_tool

View file

@ -1,3 +1,7 @@
# 2.0.0
* Upgrade dependencies to Angel 2 + file@5.
* Replace `useStream` with `useBuffer`.
# 1.3.0+1 # 1.3.0+1
* Dart 2 fixes. * Dart 2 fixes.
* Enable optionally writing responses to the buffer instead of streaming. * Enable optionally writing responses to the buffer instead of streaming.

View file

@ -9,7 +9,7 @@ In `pubspec.yaml`:
```yaml ```yaml
dependencies: dependencies:
angel_static: ^1.3.0-alpha angel_static: ^2.0.0-alpha
``` ```
# Usage # Usage

View file

@ -12,7 +12,7 @@ main() async {
allowDirectoryListing: true, allowDirectoryListing: true,
source: fs.directory(fs.currentDirectory), source: fs.directory(fs.currentDirectory),
); );
app.use(vDir.handleRequest); app.fallback(vDir.handleRequest);
var server = await http.startServer('127.0.0.1', 3000); var server = await http.startServer('127.0.0.1', 3000);
print('Listening at http://${server.address.address}:${server.port}'); print('Listening at http://${server.address.address}:${server.port}');

View file

@ -59,7 +59,7 @@ class CachingVirtualDirectory extends VirtualDirectory {
this.onlyInProduction: false, this.onlyInProduction: false,
this.useEtags: true, this.useEtags: true,
bool allowDirectoryListing, bool allowDirectoryListing,
bool useStream, bool useBuffer,
String publicPath, String publicPath,
callback(File file, RequestContext req, ResponseContext res)}) callback(File file, RequestContext req, ResponseContext res)})
: super(app, fileSystem, : super(app, fileSystem,
@ -68,7 +68,7 @@ class CachingVirtualDirectory extends VirtualDirectory {
publicPath: publicPath ?? '/', publicPath: publicPath ?? '/',
callback: callback, callback: callback,
allowDirectoryListing: allowDirectoryListing, allowDirectoryListing: allowDirectoryListing,
useStream: useStream); useBuffer: useBuffer);
@override @override
Future<bool> serveFile( Future<bool> serveFile(

View file

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/angel_framework.dart';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:http_parser/http_parser.dart';
import 'package:mime/mime.dart'; import 'package:mime/mime.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
@ -49,7 +50,7 @@ class VirtualDirectory {
/// If `true` (default: `true`), then files will be opened as streams and piped into the request. /// If `true` (default: `true`), then files will be opened as streams and piped into the request.
/// ///
/// If not, the response buffer will be used instead. /// If not, the response buffer will be used instead.
final bool useStream; final bool useBuffer;
VirtualDirectory(this.app, this.fileSystem, VirtualDirectory(this.app, this.fileSystem,
{Directory source, {Directory source,
@ -57,7 +58,7 @@ class VirtualDirectory {
this.publicPath: '/', this.publicPath: '/',
this.callback, this.callback,
this.allowDirectoryListing: false, this.allowDirectoryListing: false,
this.useStream: true}) { this.useBuffer: true}) {
_prefix = publicPath.replaceAll(_straySlashes, ''); _prefix = publicPath.replaceAll(_straySlashes, '');
if (source != null) { if (source != null) {
_source = source; _source = source;
@ -83,7 +84,7 @@ class VirtualDirectory {
/// You can also limit this functionality to specific values of the `Accept` header, ex. `text/html`. /// You can also limit this functionality to specific values of the `Accept` header, ex. `text/html`.
/// If [accepts] is `null`, OR at least one of the content types in [accepts] is present, /// If [accepts] is `null`, OR at least one of the content types in [accepts] is present,
/// the view will be served. /// the view will be served.
RequestMiddleware pushState(String path, {Iterable accepts}) { RequestHandler pushState(String path, {Iterable accepts}) {
var vPath = path.replaceAll(_straySlashes, ''); var vPath = path.replaceAll(_straySlashes, '');
if (_prefix?.isNotEmpty == true) vPath = '$_prefix/$vPath'; if (_prefix?.isNotEmpty == true) vPath = '$_prefix/$vPath';
@ -120,12 +121,12 @@ class VirtualDirectory {
/// Writes the file at the path given by the [stat] to a response. /// Writes the file at the path given by the [stat] to a response.
Future<bool> serveStat(String absolute, String relative, FileStat stat, Future<bool> serveStat(String absolute, String relative, FileStat stat,
RequestContext req, ResponseContext res) async { RequestContext req, ResponseContext res) async {
if (stat.type == FileSystemEntityType.DIRECTORY) if (stat.type == FileSystemEntityType.directory)
return await serveDirectory( return await serveDirectory(
fileSystem.directory(absolute), relative, stat, req, res); fileSystem.directory(absolute), relative, stat, req, res);
else if (stat.type == FileSystemEntityType.FILE) else if (stat.type == FileSystemEntityType.file)
return await serveFile(fileSystem.file(absolute), stat, req, res); return await serveFile(fileSystem.file(absolute), stat, req, res);
else if (stat.type == FileSystemEntityType.LINK) { else if (stat.type == FileSystemEntityType.link) {
var link = fileSystem.link(absolute); var link = fileSystem.link(absolute);
return await servePath(await link.resolveSymbolicLinks(), req, res); return await servePath(await link.resolveSymbolicLinks(), req, res);
} else } else
@ -144,7 +145,7 @@ class VirtualDirectory {
} }
if (allowDirectoryListing == true) { if (allowDirectoryListing == true) {
res.headers['content-type'] = 'text/html'; res.contentType = new MediaType('text', 'html');
res res
..write('<!DOCTYPE html>') ..write('<!DOCTYPE html>')
..write('<html>') ..write('<html>')
@ -226,12 +227,12 @@ class VirtualDirectory {
var type = lookupMimeType(file.path) ?? 'application/octet-stream'; var type = lookupMimeType(file.path) ?? 'application/octet-stream';
_ensureContentTypeAllowed(type, req); _ensureContentTypeAllowed(type, req);
res.headers['content-type'] = type; res.contentType = new MediaType.parse(type);
if (useStream != true) { if (useBuffer == true) {
res.buffer.add(await file.readAsBytes()); await res.sendFile(file);
} else { } else {
await file.openRead().pipe(res); await res.streamFile(file);
} }
return false; return false;

View file

@ -4,16 +4,15 @@ environment:
sdk: ">=1.8.0 <3.0.0" sdk: ">=1.8.0 <3.0.0"
homepage: https://github.com/angel-dart/static homepage: https://github.com/angel-dart/static
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
version: 1.3.0+1 version: 2.0.0-alpha
dependencies: dependencies:
angel_framework: ^1.1.0-alpha angel_framework: ^2.0.0-alpha
dart2_constant: ^1.0.0 file: ^5.0.0
file: ^2.0.0
intl: ">=0.0.0 <1.0.0" intl: ">=0.0.0 <1.0.0"
mime: ^0.9.3 mime: ^0.9.3
path: ^1.4.2 path: ^1.4.2
dev_dependencies: dev_dependencies:
angel_test: ^1.1.0-alpha angel_test: ^2.0.0-alpha
http: ^0.11.3 http: ^0.11.3
mustache4dart: ^1.1.0 mustache4dart: ^3.0.0-dev.0.0
test: ^0.12.13 test: ^1.0.0

View file

@ -18,21 +18,21 @@ main() {
http = new AngelHttp(app); http = new AngelHttp(app);
app.logger = new Logger('angel')..onRecord.listen(print); app.logger = new Logger('angel')..onRecord.listen(print);
app.use( app.fallback(
new VirtualDirectory(app, const LocalFileSystem(), new VirtualDirectory(app, const LocalFileSystem(),
source: testDir, source: testDir,
publicPath: '/virtual', publicPath: '/virtual',
indexFileNames: ['index.txt']).handleRequest, indexFileNames: ['index.txt']).handleRequest,
); );
app.use( app.fallback(
new VirtualDirectory(app, const LocalFileSystem(), new VirtualDirectory(app, const LocalFileSystem(),
source: testDir, source: testDir,
useStream: false, useBuffer: true,
indexFileNames: ['index.php', 'index.txt']).handleRequest, indexFileNames: ['index.php', 'index.txt']).handleRequest,
); );
app.use('Fallback'); app.fallback((req, res) => 'Fallback');
app.dumpTree(showMatchers: true); app.dumpTree(showMatchers: true);

View file

@ -10,7 +10,7 @@ main() async {
app = new Angel(); app = new Angel();
http = new AngelHttp(app); http = new AngelHttp(app);
app.use( app.fallback(
new CachingVirtualDirectory(app, const LocalFileSystem(), new CachingVirtualDirectory(app, const LocalFileSystem(),
source: testDir, source: testDir,
maxAge: 350, maxAge: 350,
@ -18,7 +18,7 @@ main() async {
indexFileNames: ['index.txt']).handleRequest, indexFileNames: ['index.txt']).handleRequest,
); );
app.get('*', 'Fallback'); app.get('*', (req, res) => 'Fallback');
app.dumpTree(showMatchers: true); app.dumpTree(showMatchers: true);

View file

@ -18,14 +18,14 @@ main() {
app = new Angel(); app = new Angel();
http = new AngelHttp(app); http = new AngelHttp(app);
app.use( app.fallback(
new CachingVirtualDirectory(app, const LocalFileSystem(), new CachingVirtualDirectory(app, const LocalFileSystem(),
source: testDir, maxAge: 350, onlyInProduction: false, source: testDir, maxAge: 350, onlyInProduction: false,
//publicPath: '/virtual', //publicPath: '/virtual',
indexFileNames: ['index.txt']).handleRequest, indexFileNames: ['index.txt']).handleRequest,
); );
app.get('*', 'Fallback'); app.get('*', (req, res) => 'Fallback');
app.dumpTree(showMatchers: true); app.dumpTree(showMatchers: true);

View file

@ -26,7 +26,7 @@ main() async {
var app = new Angel(); var app = new Angel();
app.logger = new Logger('angel')..onRecord.listen(print); app.logger = new Logger('angel')..onRecord.listen(print);
app.use( app.fallback(
new VirtualDirectory(app, const LocalFileSystem(), new VirtualDirectory(app, const LocalFileSystem(),
source: swaggerUiDistDir, publicPath: 'swagger/') source: swaggerUiDistDir, publicPath: 'swagger/')
.handleRequest, .handleRequest,

View file

@ -28,9 +28,9 @@ main() {
); );
app app
..use(vDir.handleRequest) ..fallback(vDir.handleRequest)
..use(vDir.pushState('index.html')) ..fallback(vDir.pushState('index.html'))
..use('Fallback'); ..fallback((req, res) => 'Fallback');
app.logger = new Logger('push_state') app.logger = new Logger('push_state')
..onRecord.listen( ..onRecord.listen(