Port to using angelEnv
This commit is contained in:
parent
05199ce342
commit
a4fd32581b
3 changed files with 19 additions and 9 deletions
|
@ -1,5 +1,8 @@
|
||||||
# 2.0.0-rc.0
|
# 2.0.0-rc.0
|
||||||
* Log a warning when no `reflector` is provided.
|
* Log a warning when no `reflector` is provided.
|
||||||
|
* Add `AngelEnvironment` class.
|
||||||
|
* Add `Angel.environment`.
|
||||||
|
* Deprecated `app.isProduction` in favor of `app.environment.isProduction`.
|
||||||
|
|
||||||
# 2.0.0-alpha.24
|
# 2.0.0-alpha.24
|
||||||
* Add `AngelEnv` class to `core`.
|
* Add `AngelEnv` class to `core`.
|
||||||
|
|
|
@ -113,7 +113,7 @@ abstract class Driver<
|
||||||
}
|
}
|
||||||
|
|
||||||
var cacheKey = req.method + path;
|
var cacheKey = req.method + path;
|
||||||
var tuple = app.isProduction
|
var tuple = app.environment.isProduction
|
||||||
? app.handlerCache.putIfAbsent(cacheKey, resolveTuple)
|
? app.handlerCache.putIfAbsent(cacheKey, resolveTuple)
|
||||||
: resolveTuple();
|
: resolveTuple();
|
||||||
var line = tuple.item4 as MiddlewarePipeline<RequestHandler>;
|
var line = tuple.item4 as MiddlewarePipeline<RequestHandler>;
|
||||||
|
@ -129,7 +129,7 @@ abstract class Driver<
|
||||||
..registerSingleton<ParseResult<RouteResult>>(tuple.item3)
|
..registerSingleton<ParseResult<RouteResult>>(tuple.item3)
|
||||||
..registerSingleton<ParseResult>(tuple.item3);
|
..registerSingleton<ParseResult>(tuple.item3);
|
||||||
|
|
||||||
if (!app.isProduction && app.logger != null) {
|
if (!app.environment.isProduction && app.logger != null) {
|
||||||
req.container
|
req.container
|
||||||
.registerSingleton<Stopwatch>(new Stopwatch()..start());
|
.registerSingleton<Stopwatch>(new Stopwatch()..start());
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ abstract class Driver<
|
||||||
ResponseContext res,
|
ResponseContext res,
|
||||||
{bool ignoreFinalizers = false}) {
|
{bool ignoreFinalizers = false}) {
|
||||||
void _cleanup(_) {
|
void _cleanup(_) {
|
||||||
if (!app.isProduction && app.logger != null) {
|
if (!app.environment.isProduction && app.logger != null) {
|
||||||
var sw = req.container.make<Stopwatch>();
|
var sw = req.container.make<Stopwatch>();
|
||||||
app.logger.info(
|
app.logger.info(
|
||||||
"${res.statusCode} ${req.method} ${req.uri} (${sw?.elapsedMilliseconds ?? 'unknown'} ms)");
|
"${res.statusCode} ${req.method} ${req.uri} (${sw?.elapsedMilliseconds ?? 'unknown'} ms)");
|
||||||
|
|
|
@ -72,7 +72,8 @@ class Angel extends Routable {
|
||||||
/// A set of [Controller] objects that have been loaded into the application.
|
/// A set of [Controller] objects that have been loaded into the application.
|
||||||
Map<Pattern, Controller> get controllers => _controllers;
|
Map<Pattern, Controller> get controllers => _controllers;
|
||||||
|
|
||||||
/// Now *deprecated*, in favor of [AngelEnv] and [angelEnv].
|
/// Now *deprecated*, in favor of [AngelEnv] and [angelEnv]. Use `app.environment.isProduction`
|
||||||
|
/// instead.
|
||||||
///
|
///
|
||||||
/// Indicates whether the application is running in a production environment.
|
/// Indicates whether the application is running in a production environment.
|
||||||
///
|
///
|
||||||
|
@ -82,7 +83,12 @@ class Angel extends Routable {
|
||||||
/// This value is memoized the first time you call it, so do not change environment
|
/// This value is memoized the first time you call it, so do not change environment
|
||||||
/// configuration at runtime!
|
/// configuration at runtime!
|
||||||
@deprecated
|
@deprecated
|
||||||
bool get isProduction => angelEnv.isProduction;
|
bool get isProduction => environment.isProduction;
|
||||||
|
|
||||||
|
/// The [AngelEnvironment] in which the application is running.
|
||||||
|
///
|
||||||
|
/// By default, it is automatically inferred.
|
||||||
|
final AngelEnvironment environment;
|
||||||
|
|
||||||
/// Returns the parent instance of this application, if any.
|
/// Returns the parent instance of this application, if any.
|
||||||
Angel get parent => _parent;
|
Angel get parent => _parent;
|
||||||
|
@ -213,14 +219,14 @@ class Angel extends Routable {
|
||||||
String header: 'Dumping route tree:',
|
String header: 'Dumping route tree:',
|
||||||
String tab: ' ',
|
String tab: ' ',
|
||||||
bool showMatchers: false}) {
|
bool showMatchers: false}) {
|
||||||
if (isProduction) {
|
if (environment.isProduction) {
|
||||||
_flattened ??= flatten(this);
|
_flattened ??= flatten(this);
|
||||||
|
|
||||||
_flattened.dumpTree(
|
_flattened.dumpTree(
|
||||||
callback: callback,
|
callback: callback,
|
||||||
header: header?.isNotEmpty == true
|
header: header?.isNotEmpty == true
|
||||||
? header
|
? header
|
||||||
: (isProduction
|
: (environment.isProduction
|
||||||
? 'Dumping flattened route tree:'
|
? 'Dumping flattened route tree:'
|
||||||
: 'Dumping route tree:'),
|
: 'Dumping route tree:'),
|
||||||
tab: tab ?? ' ');
|
tab: tab ?? ' ');
|
||||||
|
@ -229,7 +235,7 @@ class Angel extends Routable {
|
||||||
callback: callback,
|
callback: callback,
|
||||||
header: header?.isNotEmpty == true
|
header: header?.isNotEmpty == true
|
||||||
? header
|
? header
|
||||||
: (isProduction
|
: (environment.isProduction
|
||||||
? 'Dumping flattened route tree:'
|
? 'Dumping flattened route tree:'
|
||||||
: 'Dumping route tree:'),
|
: 'Dumping route tree:'),
|
||||||
tab: tab ?? ' ');
|
tab: tab ?? ' ');
|
||||||
|
@ -287,7 +293,7 @@ class Angel extends Routable {
|
||||||
///
|
///
|
||||||
/// You may [force] the optimization to run, if you are not running in production.
|
/// You may [force] the optimization to run, if you are not running in production.
|
||||||
void optimizeForProduction({bool force: false}) {
|
void optimizeForProduction({bool force: false}) {
|
||||||
if (isProduction == true || force == true) {
|
if (environment.isProduction || force == true) {
|
||||||
_flattened ??= flatten(this);
|
_flattened ??= flatten(this);
|
||||||
logger?.info('Angel is running in production mode.');
|
logger?.info('Angel is running in production mode.');
|
||||||
}
|
}
|
||||||
|
@ -349,6 +355,7 @@ class Angel extends Routable {
|
||||||
|
|
||||||
Angel(
|
Angel(
|
||||||
{Reflector reflector: const EmptyReflector(),
|
{Reflector reflector: const EmptyReflector(),
|
||||||
|
this.environment: angelEnv,
|
||||||
this.logger,
|
this.logger,
|
||||||
this.allowMethodOverrides: true,
|
this.allowMethodOverrides: true,
|
||||||
this.serializer,
|
this.serializer,
|
||||||
|
|
Loading…
Reference in a new issue