2018-07-09 06:14:25 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
import 'package:angel_seo/angel_seo.dart';
|
|
|
|
import 'package:angel_static/angel_static.dart';
|
2018-07-09 13:49:25 +00:00
|
|
|
import 'package:dart2_constant/convert.dart';
|
2018-07-09 06:14:25 +00:00
|
|
|
import 'package:file/local.dart';
|
|
|
|
|
|
|
|
main() async {
|
|
|
|
var app = new Angel()..lazyParseBodies = true;
|
|
|
|
var fs = const LocalFileSystem();
|
|
|
|
var http = new AngelHttp(app);
|
|
|
|
|
2018-07-09 13:49:25 +00:00
|
|
|
// You can wrap a [VirtualDirectory]
|
|
|
|
var vDir = inlineAssetsFromVirtualDirectory(
|
2018-07-09 06:14:25 +00:00
|
|
|
new VirtualDirectory(
|
|
|
|
app,
|
|
|
|
fs,
|
|
|
|
source: fs.directory('web'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
app.use(vDir.handleRequest);
|
|
|
|
|
2018-07-09 13:49:25 +00:00
|
|
|
// OR, just add a finalizer. Note that [VirtualDirectory] *streams* its response,
|
|
|
|
// so a response finalizer does not touch its contents.
|
|
|
|
//
|
|
|
|
// You likely won't need to use both; it just depends on your use case.
|
|
|
|
app.responseFinalizers.add(inlineAssets(fs.directory('web')));
|
|
|
|
|
|
|
|
app.get('/using_response_buffer', (ResponseContext res) async {
|
|
|
|
var indexHtml = fs.directory('web').childFile('index.html');
|
|
|
|
var contents = await indexHtml.readAsString();
|
|
|
|
res
|
|
|
|
..headers['content-type'] = 'text/html; charset=utf-8'
|
|
|
|
..buffer.add(utf8.encode(contents));
|
|
|
|
});
|
|
|
|
|
2018-07-09 06:14:25 +00:00
|
|
|
app.use(() => throw new AngelHttpException.notFound());
|
|
|
|
|
|
|
|
var server = await http.startServer('127.0.0.1', 3000);
|
|
|
|
print('Listening at http://${server.address.address}:${server.port}');
|
|
|
|
}
|