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 {
|
main() async {
|
||||||
// Watch the config/ and web/ directories for changes, and hot-reload the server.
|
// Watch the config/ and web/ directories for changes, and hot-reload the server.
|
||||||
var hot = new HotReloader(() async {
|
var hot = new HotReloader(() async {
|
||||||
var app = new Angel()..lazyParseBodies = true;
|
var app = new Angel();
|
||||||
await app.configure(configureServer);
|
await app.configure(configureServer);
|
||||||
hierarchicalLoggingEnabled = true;
|
hierarchicalLoggingEnabled = true;
|
||||||
app.logger = new Logger('angel');
|
app.logger = new Logger('angel');
|
||||||
|
|
|
@ -1,47 +1,4 @@
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:isolate';
|
|
||||||
import 'package:angel/angel.dart';
|
import 'package:angel/angel.dart';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_production/angel_production.dart';
|
||||||
import 'package:logging/logging.dart';
|
|
||||||
|
|
||||||
const String hostname = '127.0.0.1';
|
main(List<String> args) => new Runner('angel', configureServer).run(args);
|
||||||
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}');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/// This app's route configuration.
|
/// This app's route configuration.
|
||||||
library angel.src.routes;
|
library angel.src.routes;
|
||||||
|
|
||||||
import 'package:angel_cors/angel_cors.dart';
|
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_static/angel_static.dart';
|
import 'package:angel_static/angel_static.dart';
|
||||||
import 'package:file/file.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
|
/// * https://github.com/angel-dart/angel/wiki/Requests-&-Responses
|
||||||
AngelConfigurer configureServer(FileSystem fileSystem) {
|
AngelConfigurer configureServer(FileSystem fileSystem) {
|
||||||
return (Angel app) async {
|
return (Angel app) async {
|
||||||
// Enable CORS
|
|
||||||
app.use(cors());
|
|
||||||
|
|
||||||
// Typically, you want to mount controllers first, after any global middleware.
|
// Typically, you want to mount controllers first, after any global middleware.
|
||||||
await app.configure(controllers.configureServer);
|
await app.configure(controllers.configureServer);
|
||||||
|
|
||||||
|
@ -39,11 +35,11 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
||||||
fileSystem,
|
fileSystem,
|
||||||
source: fileSystem.directory('web'),
|
source: fileSystem.directory('web'),
|
||||||
);
|
);
|
||||||
app.use(vDir.handleRequest);
|
app.fallback(vDir.handleRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Throw a 404 if no route matched the request.
|
// 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.
|
// Set our application up to handle different errors.
|
||||||
//
|
//
|
||||||
|
|
23
pubspec.yaml
23
pubspec.yaml
|
@ -1,20 +1,19 @@
|
||||||
name: angel
|
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! ;)
|
publish_to: none # Ensure we don't accidentally publish our private code! ;)
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.0.0-dev <3.0.0'
|
sdk: '>=2.0.0-dev <3.0.0'
|
||||||
homepage: https://github.com/angel-dart/angel
|
homepage: https://github.com/angel-dart/angel
|
||||||
dependencies:
|
dependencies:
|
||||||
angel_auth: ^1.1.0 # Supports stateless authentication via JWT
|
angel_auth: ^2.0.0-alpha # Supports stateless authentication via JWT
|
||||||
angel_configuration: ^1.2.0 # Loads application configuration, along with support for .env files.
|
angel_configuration: ^2.0.0 # Loads application configuration, along with support for .env files.
|
||||||
angel_cors: ^1.0.0 # CORS support
|
angel_framework: ^2.0.0-alpha # The core server library.
|
||||||
angel_framework: ^1.1.0 # The core server library.
|
angel_jael: ^2.0.0 # Server-side templating engine
|
||||||
angel_jael: ^1.0.0 # Server-side templating engine
|
angel_production: ^1.0.0-alpha
|
||||||
angel_static: ^1.3.0 # Static file server
|
angel_static: ^2.0.0-alpha # Static file server
|
||||||
angel_validate: ^1.0.0 # Allows for validation of input data
|
angel_validate: ^2.0.0-alpha # Allows for validation of input data
|
||||||
dart2_constant: ^1.0.0 # For backwards compatibility.
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
angel_hot: ^1.1.0 # Hot-reloading support. :)
|
angel_hot: ^2.0.0 # Hot-reloading support. :)
|
||||||
angel_test: ^1.1.0 # Utilities for testing Angel servers.
|
angel_test: ^2.0.0-alpha # Utilities for testing Angel servers.
|
||||||
io: ^0.3.2
|
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">
|
<block name="content">
|
||||||
<div class="title">{{ message }}</div>
|
<div class="title">{{ message }}</div>
|
||||||
</block>
|
</block>
|
|
@ -1,4 +1,4 @@
|
||||||
<extend src="layout.jl">
|
<extend src="layout.jael">
|
||||||
<block name="content">
|
<block name="content">
|
||||||
<div class="title">Angel</div>
|
<div class="title">Angel</div>
|
||||||
</block>
|
</block>
|
Loading…
Reference in a new issue