1.2.3
This commit is contained in:
parent
ea3d209a93
commit
a55f97c871
7 changed files with 86 additions and 5 deletions
3
CHANGELOG.md
Normal file
3
CHANGELOG.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# 1.2.3
|
||||
Fixed #40 and #41, which dealt with paths being improperly served when using a
|
||||
`publicPath`.
|
|
@ -107,8 +107,8 @@ class VirtualDirectory implements AngelPlugin {
|
|||
void serve(Router router) {
|
||||
// _printDebug('Source directory: ${source.absolute.path}');
|
||||
// _printDebug('Public path prefix: "$_prefix"');
|
||||
router.get('$publicPath/*',
|
||||
(RequestContext req, ResponseContext res) async {
|
||||
//router.get('$publicPath/*',
|
||||
router.get('$_prefix/*', (RequestContext req, ResponseContext res) async {
|
||||
var path = req.path.replaceAll(_straySlashes, '');
|
||||
return servePath(path, req, res);
|
||||
});
|
||||
|
@ -124,7 +124,7 @@ class VirtualDirectory implements AngelPlugin {
|
|||
}
|
||||
|
||||
close() async {
|
||||
if (!_transformerLoad.isCompleted) {
|
||||
if (!_transformerLoad.isCompleted && _transformers.isNotEmpty) {
|
||||
_transformerLoad.completeError(new StateError(
|
||||
'VirtualDirectory was closed before all transformers loaded.'));
|
||||
}
|
||||
|
@ -176,10 +176,13 @@ class VirtualDirectory implements AngelPlugin {
|
|||
|
||||
servePath(String path, RequestContext req, ResponseContext res) async {
|
||||
if (_prefix.isNotEmpty) {
|
||||
path = path.replaceAll(new RegExp('^' + _pathify(_prefix)), '');
|
||||
// Only replace the *first* incidence
|
||||
// Resolve: https://github.com/angel-dart/angel/issues/41
|
||||
path = path.replaceFirst(new RegExp('^' + _pathify(_prefix)), '');
|
||||
}
|
||||
|
||||
if (path.isEmpty) path = '.';
|
||||
path = path.replaceAll(_straySlashes, '');
|
||||
|
||||
var absolute = source.absolute.uri.resolve(path).toFilePath();
|
||||
var stat = await FileStat.stat(absolute);
|
||||
|
|
|
@ -4,7 +4,7 @@ environment:
|
|||
sdk: ">=1.19.0"
|
||||
homepage: https://github.com/angel-dart/static
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
version: 1.2.2+4
|
||||
version: 1.2.3
|
||||
dependencies:
|
||||
angel_framework: ^1.0.0-dev
|
||||
cli_util: ^0.1.1
|
||||
|
|
61
test/issue41_test.dart
Normal file
61
test/issue41_test.dart
Normal file
|
@ -0,0 +1,61 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:angel_diagnostics/angel_diagnostics.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_static/angel_static.dart';
|
||||
import 'package:angel_test/angel_test.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
final Directory swaggerUiDistDir =
|
||||
new Directory('test/node_modules/swagger-ui-dist');
|
||||
|
||||
main() async {
|
||||
TestClient client;
|
||||
String swaggerUiCssContents, swaggerTestJsContents;
|
||||
|
||||
setUp(() async {
|
||||
// Load file contents
|
||||
swaggerUiCssContents =
|
||||
await new File.fromUri(swaggerUiDistDir.uri.resolve('swagger-ui.css'))
|
||||
.readAsString();
|
||||
swaggerTestJsContents =
|
||||
await new File.fromUri(swaggerUiDistDir.uri.resolve('test.js'))
|
||||
.readAsString();
|
||||
|
||||
// Initialize app
|
||||
var app = new Angel();
|
||||
await Future.forEach([
|
||||
new VirtualDirectory(source: swaggerUiDistDir, publicPath: 'swagger/'),
|
||||
logRequests()
|
||||
], app.configure);
|
||||
|
||||
app.dumpTree();
|
||||
client = await connectTo(app);
|
||||
});
|
||||
|
||||
tearDown(() => client.close());
|
||||
|
||||
test('prefix is not replaced in file paths', () async {
|
||||
var response = await client.get('/swagger/swagger-ui.css');
|
||||
print('Response: ${response.body}');
|
||||
expect(response, hasBody(swaggerUiCssContents));
|
||||
});
|
||||
|
||||
test('get a file without prefix in name', () async {
|
||||
var response = await client.get('/swagger/test.js');
|
||||
print('Response: ${response.body}');
|
||||
expect(response, hasBody(swaggerTestJsContents));
|
||||
});
|
||||
|
||||
test('trailing slash at root', () async {
|
||||
var response = await client.get('/swagger');
|
||||
var body1 = response.body;
|
||||
print('Response #1: $body1');
|
||||
|
||||
response = await client.get('/swagger/');
|
||||
var body2 = response.body;
|
||||
print('Response #2: $body2');
|
||||
|
||||
expect(body1, body2);
|
||||
});
|
||||
}
|
10
test/node_modules/swagger-ui-dist/index.html
generated
vendored
Normal file
10
test/node_modules/swagger-ui-dist/index.html
generated
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Swagger...</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello!</h1>
|
||||
<i>Hooray for testing...</i>
|
||||
</body>
|
||||
</html>
|
3
test/node_modules/swagger-ui-dist/swagger-ui.css
generated
vendored
Normal file
3
test/node_modules/swagger-ui-dist/swagger-ui.css
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
html, body {
|
||||
font-weight: bold;
|
||||
}
|
1
test/node_modules/swagger-ui-dist/test.js
generated
vendored
Normal file
1
test/node_modules/swagger-ui-dist/test.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
console.log('foo');
|
Loading…
Reference in a new issue