merge from 2.x
This commit is contained in:
commit
db6e5f2039
7 changed files with 18 additions and 66 deletions
|
@ -8,7 +8,7 @@ import 'package:logging/logging.dart';
|
|||
main() async {
|
||||
// Watch the config/ and web/ directories for changes, and hot-reload the server.
|
||||
var hot = new HotReloader(() async {
|
||||
var app = new Angel()..lazyParseBodies = true;
|
||||
var app = new Angel();
|
||||
await app.configure(configureServer);
|
||||
hierarchicalLoggingEnabled = true;
|
||||
app.logger = new Logger('angel');
|
||||
|
|
|
@ -1,47 +1,4 @@
|
|||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'package:angel/angel.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:angel_production/angel_production.dart';
|
||||
|
||||
const String hostname = '127.0.0.1';
|
||||
const int port = 3000;
|
||||
|
||||
void main() {
|
||||
// Start a server instance in multiple isolates.
|
||||
|
||||
for (int id = 0; id < Platform.numberOfProcessors; id++)
|
||||
Isolate.spawn(isolateMain, id);
|
||||
|
||||
isolateMain(Platform.numberOfProcessors);
|
||||
}
|
||||
|
||||
void isolateMain(int id) {
|
||||
var app = new Angel();
|
||||
|
||||
app.configure(configureServer).then((_) async {
|
||||
// In production, we'll want to log errors to a file.
|
||||
// Alternatives include sending logs to a service like Sentry.
|
||||
hierarchicalLoggingEnabled = true;
|
||||
app.logger = new Logger('angel')
|
||||
..onRecord.listen((rec) {
|
||||
if (rec.error == null) {
|
||||
stdout.writeln(rec);
|
||||
} else {
|
||||
var err = rec.error;
|
||||
if (err is AngelHttpException && err.statusCode != 500) return;
|
||||
var sink = stderr;
|
||||
sink..writeln(rec)..writeln(rec.error)..writeln(rec.stackTrace);
|
||||
}
|
||||
});
|
||||
|
||||
// Passing `startShared` to the constructor allows us to start multiple
|
||||
// instances of our application concurrently, listening on a single port.
|
||||
//
|
||||
// This effectively lets us multi-thread the application.
|
||||
var http = new AngelHttp.custom(app, startShared);
|
||||
var server = await http.startServer(hostname, port);
|
||||
print(
|
||||
'Instance #$id listening at http://${server.address.address}:${server.port}');
|
||||
});
|
||||
}
|
||||
main(List<String> args) => new Runner('angel', configureServer).run(args);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// This app's route configuration.
|
||||
library angel.src.routes;
|
||||
|
||||
import 'package:angel_cors/angel_cors.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_static/angel_static.dart';
|
||||
import 'package:file/file.dart';
|
||||
|
@ -14,9 +13,6 @@ import 'controllers/controllers.dart' as controllers;
|
|||
/// * https://github.com/angel-dart/angel/wiki/Requests-&-Responses
|
||||
AngelConfigurer configureServer(FileSystem fileSystem) {
|
||||
return (Angel app) async {
|
||||
// Enable CORS
|
||||
app.use(cors());
|
||||
|
||||
// Typically, you want to mount controllers first, after any global middleware.
|
||||
await app.configure(controllers.configureServer);
|
||||
|
||||
|
@ -39,11 +35,11 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
|||
fileSystem,
|
||||
source: fileSystem.directory('web'),
|
||||
);
|
||||
app.use(vDir.handleRequest);
|
||||
app.fallback(vDir.handleRequest);
|
||||
}
|
||||
|
||||
// Throw a 404 if no route matched the request.
|
||||
app.use(() => throw new AngelHttpException.notFound());
|
||||
app.fallback((req, res) => throw new AngelHttpException.notFound());
|
||||
|
||||
// Set our application up to handle different errors.
|
||||
//
|
||||
|
|
23
pubspec.yaml
23
pubspec.yaml
|
@ -1,20 +1,19 @@
|
|||
name: angel
|
||||
description: An easily-extensible web server framework in Dart.
|
||||
description: An app that's going to be amazing pretty soon.
|
||||
publish_to: none # Ensure we don't accidentally publish our private code! ;)
|
||||
environment:
|
||||
sdk: '>=2.0.0-dev <3.0.0'
|
||||
homepage: https://github.com/angel-dart/angel
|
||||
dependencies:
|
||||
angel_auth: ^1.1.0 # Supports stateless authentication via JWT
|
||||
angel_configuration: ^1.2.0 # Loads application configuration, along with support for .env files.
|
||||
angel_cors: ^1.0.0 # CORS support
|
||||
angel_framework: ^1.1.0 # The core server library.
|
||||
angel_jael: ^1.0.0 # Server-side templating engine
|
||||
angel_static: ^1.3.0 # Static file server
|
||||
angel_validate: ^1.0.0 # Allows for validation of input data
|
||||
dart2_constant: ^1.0.0 # For backwards compatibility.
|
||||
angel_auth: ^2.0.0-alpha # Supports stateless authentication via JWT
|
||||
angel_configuration: ^2.0.0 # Loads application configuration, along with support for .env files.
|
||||
angel_framework: ^2.0.0-alpha # The core server library.
|
||||
angel_jael: ^2.0.0 # Server-side templating engine
|
||||
angel_production: ^1.0.0-alpha
|
||||
angel_static: ^2.0.0-alpha # Static file server
|
||||
angel_validate: ^2.0.0-alpha # Allows for validation of input data
|
||||
dev_dependencies:
|
||||
angel_hot: ^1.1.0 # Hot-reloading support. :)
|
||||
angel_test: ^1.1.0 # Utilities for testing Angel servers.
|
||||
angel_hot: ^2.0.0 # Hot-reloading support. :)
|
||||
angel_test: ^2.0.0-alpha # Utilities for testing Angel servers.
|
||||
io: ^0.3.2
|
||||
test: ^0.12.13
|
||||
test: ^1.0.0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<extend src="layout.jl">
|
||||
<extend src="layout.jael">
|
||||
<block name="content">
|
||||
<div class="title">{{ message }}</div>
|
||||
</block>
|
|
@ -1,4 +1,4 @@
|
|||
<extend src="layout.jl">
|
||||
<extend src="layout.jael">
|
||||
<block name="content">
|
||||
<div class="title">Angel</div>
|
||||
</block>
|
Loading…
Reference in a new issue