Bump to 2.0.0-alpha
This commit is contained in:
parent
5288b5065f
commit
2e8573cd96
12 changed files with 39 additions and 34 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -63,3 +63,4 @@ packages
|
|||
# Include when developing application packages.
|
||||
pubspec.lock
|
||||
|
||||
.dart_tool
|
|
@ -1,3 +1,7 @@
|
|||
# 2.0.0
|
||||
* Upgrade dependencies to Angel 2 + file@5.
|
||||
* Replace `useStream` with `useBuffer`.
|
||||
|
||||
# 1.3.0+1
|
||||
* Dart 2 fixes.
|
||||
* Enable optionally writing responses to the buffer instead of streaming.
|
||||
|
|
|
@ -9,7 +9,7 @@ In `pubspec.yaml`:
|
|||
|
||||
```yaml
|
||||
dependencies:
|
||||
angel_static: ^1.3.0-alpha
|
||||
angel_static: ^2.0.0-alpha
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
|
|
@ -12,7 +12,7 @@ main() async {
|
|||
allowDirectoryListing: true,
|
||||
source: fs.directory(fs.currentDirectory),
|
||||
);
|
||||
app.use(vDir.handleRequest);
|
||||
app.fallback(vDir.handleRequest);
|
||||
|
||||
var server = await http.startServer('127.0.0.1', 3000);
|
||||
print('Listening at http://${server.address.address}:${server.port}');
|
||||
|
|
|
@ -59,7 +59,7 @@ class CachingVirtualDirectory extends VirtualDirectory {
|
|||
this.onlyInProduction: false,
|
||||
this.useEtags: true,
|
||||
bool allowDirectoryListing,
|
||||
bool useStream,
|
||||
bool useBuffer,
|
||||
String publicPath,
|
||||
callback(File file, RequestContext req, ResponseContext res)})
|
||||
: super(app, fileSystem,
|
||||
|
@ -68,7 +68,7 @@ class CachingVirtualDirectory extends VirtualDirectory {
|
|||
publicPath: publicPath ?? '/',
|
||||
callback: callback,
|
||||
allowDirectoryListing: allowDirectoryListing,
|
||||
useStream: useStream);
|
||||
useBuffer: useBuffer);
|
||||
|
||||
@override
|
||||
Future<bool> serveFile(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:async';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
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 not, the response buffer will be used instead.
|
||||
final bool useStream;
|
||||
final bool useBuffer;
|
||||
|
||||
VirtualDirectory(this.app, this.fileSystem,
|
||||
{Directory source,
|
||||
|
@ -57,7 +58,7 @@ class VirtualDirectory {
|
|||
this.publicPath: '/',
|
||||
this.callback,
|
||||
this.allowDirectoryListing: false,
|
||||
this.useStream: true}) {
|
||||
this.useBuffer: true}) {
|
||||
_prefix = publicPath.replaceAll(_straySlashes, '');
|
||||
if (source != null) {
|
||||
_source = source;
|
||||
|
@ -83,7 +84,7 @@ class VirtualDirectory {
|
|||
/// 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,
|
||||
/// the view will be served.
|
||||
RequestMiddleware pushState(String path, {Iterable accepts}) {
|
||||
RequestHandler pushState(String path, {Iterable accepts}) {
|
||||
var vPath = path.replaceAll(_straySlashes, '');
|
||||
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.
|
||||
Future<bool> serveStat(String absolute, String relative, FileStat stat,
|
||||
RequestContext req, ResponseContext res) async {
|
||||
if (stat.type == FileSystemEntityType.DIRECTORY)
|
||||
if (stat.type == FileSystemEntityType.directory)
|
||||
return await serveDirectory(
|
||||
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);
|
||||
else if (stat.type == FileSystemEntityType.LINK) {
|
||||
else if (stat.type == FileSystemEntityType.link) {
|
||||
var link = fileSystem.link(absolute);
|
||||
return await servePath(await link.resolveSymbolicLinks(), req, res);
|
||||
} else
|
||||
|
@ -144,7 +145,7 @@ class VirtualDirectory {
|
|||
}
|
||||
|
||||
if (allowDirectoryListing == true) {
|
||||
res.headers['content-type'] = 'text/html';
|
||||
res.contentType = new MediaType('text', 'html');
|
||||
res
|
||||
..write('<!DOCTYPE html>')
|
||||
..write('<html>')
|
||||
|
@ -226,12 +227,12 @@ class VirtualDirectory {
|
|||
|
||||
var type = lookupMimeType(file.path) ?? 'application/octet-stream';
|
||||
_ensureContentTypeAllowed(type, req);
|
||||
res.headers['content-type'] = type;
|
||||
res.contentType = new MediaType.parse(type);
|
||||
|
||||
if (useStream != true) {
|
||||
res.buffer.add(await file.readAsBytes());
|
||||
if (useBuffer == true) {
|
||||
await res.sendFile(file);
|
||||
} else {
|
||||
await file.openRead().pipe(res);
|
||||
await res.streamFile(file);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
13
pubspec.yaml
13
pubspec.yaml
|
@ -4,16 +4,15 @@ environment:
|
|||
sdk: ">=1.8.0 <3.0.0"
|
||||
homepage: https://github.com/angel-dart/static
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
version: 1.3.0+1
|
||||
version: 2.0.0-alpha
|
||||
dependencies:
|
||||
angel_framework: ^1.1.0-alpha
|
||||
dart2_constant: ^1.0.0
|
||||
file: ^2.0.0
|
||||
angel_framework: ^2.0.0-alpha
|
||||
file: ^5.0.0
|
||||
intl: ">=0.0.0 <1.0.0"
|
||||
mime: ^0.9.3
|
||||
path: ^1.4.2
|
||||
dev_dependencies:
|
||||
angel_test: ^1.1.0-alpha
|
||||
angel_test: ^2.0.0-alpha
|
||||
http: ^0.11.3
|
||||
mustache4dart: ^1.1.0
|
||||
test: ^0.12.13
|
||||
mustache4dart: ^3.0.0-dev.0.0
|
||||
test: ^1.0.0
|
||||
|
|
|
@ -18,21 +18,21 @@ main() {
|
|||
http = new AngelHttp(app);
|
||||
app.logger = new Logger('angel')..onRecord.listen(print);
|
||||
|
||||
app.use(
|
||||
app.fallback(
|
||||
new VirtualDirectory(app, const LocalFileSystem(),
|
||||
source: testDir,
|
||||
publicPath: '/virtual',
|
||||
indexFileNames: ['index.txt']).handleRequest,
|
||||
);
|
||||
|
||||
app.use(
|
||||
app.fallback(
|
||||
new VirtualDirectory(app, const LocalFileSystem(),
|
||||
source: testDir,
|
||||
useStream: false,
|
||||
useBuffer: true,
|
||||
indexFileNames: ['index.php', 'index.txt']).handleRequest,
|
||||
);
|
||||
|
||||
app.use('Fallback');
|
||||
app.fallback((req, res) => 'Fallback');
|
||||
|
||||
app.dumpTree(showMatchers: true);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ main() async {
|
|||
app = new Angel();
|
||||
http = new AngelHttp(app);
|
||||
|
||||
app.use(
|
||||
app.fallback(
|
||||
new CachingVirtualDirectory(app, const LocalFileSystem(),
|
||||
source: testDir,
|
||||
maxAge: 350,
|
||||
|
@ -18,7 +18,7 @@ main() async {
|
|||
indexFileNames: ['index.txt']).handleRequest,
|
||||
);
|
||||
|
||||
app.get('*', 'Fallback');
|
||||
app.get('*', (req, res) => 'Fallback');
|
||||
|
||||
app.dumpTree(showMatchers: true);
|
||||
|
||||
|
|
|
@ -18,14 +18,14 @@ main() {
|
|||
app = new Angel();
|
||||
http = new AngelHttp(app);
|
||||
|
||||
app.use(
|
||||
app.fallback(
|
||||
new CachingVirtualDirectory(app, const LocalFileSystem(),
|
||||
source: testDir, maxAge: 350, onlyInProduction: false,
|
||||
//publicPath: '/virtual',
|
||||
indexFileNames: ['index.txt']).handleRequest,
|
||||
);
|
||||
|
||||
app.get('*', 'Fallback');
|
||||
app.get('*', (req, res) => 'Fallback');
|
||||
|
||||
app.dumpTree(showMatchers: true);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ main() async {
|
|||
var app = new Angel();
|
||||
app.logger = new Logger('angel')..onRecord.listen(print);
|
||||
|
||||
app.use(
|
||||
app.fallback(
|
||||
new VirtualDirectory(app, const LocalFileSystem(),
|
||||
source: swaggerUiDistDir, publicPath: 'swagger/')
|
||||
.handleRequest,
|
||||
|
|
|
@ -28,9 +28,9 @@ main() {
|
|||
);
|
||||
|
||||
app
|
||||
..use(vDir.handleRequest)
|
||||
..use(vDir.pushState('index.html'))
|
||||
..use('Fallback');
|
||||
..fallback(vDir.handleRequest)
|
||||
..fallback(vDir.pushState('index.html'))
|
||||
..fallback((req, res) => 'Fallback');
|
||||
|
||||
app.logger = new Logger('push_state')
|
||||
..onRecord.listen(
|
||||
|
|
Loading…
Reference in a new issue