From 3bff493d36edb3b52f328e832addb7f517a05243 Mon Sep 17 00:00:00 2001 From: regiostech Date: Thu, 21 Apr 2016 22:03:30 -0400 Subject: [PATCH] Default to build/web or web --- lib/angel_static.dart | 9 ++++++++- pubspec.yaml | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/angel_static.dart b/lib/angel_static.dart index 8fd5f499..1aabc93b 100644 --- a/lib/angel_static.dart +++ b/lib/angel_static.dart @@ -5,7 +5,14 @@ import 'package:angel_framework/angel_framework.dart'; import 'package:mime/mime.dart' show lookupMimeType; /// Serves files statically from a given directory. -Middleware serveStatic(Directory sourceDirectory) { +Middleware serveStatic([Directory sourceDirectory]) { + if (sourceDirectory == null) { + String dirPath = Platform.environment['ANGEL_ENV'] == 'production' + ? './build/web' + : './web'; + sourceDirectory = new Directory(dirPath); + } + return (RequestContext req, ResponseContext res) async { String requested = req.path.replaceAll(new RegExp(r'^\/'), ''); File file = new File.fromUri( diff --git a/pubspec.yaml b/pubspec.yaml index 80a0a7b8..bbfd262b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: angel_static description: Static server middleware for Angel. homepage: https://github.com/angel-dart/angel_static author: thosakwe -version: 1.0.0-beta.1 +version: 1.0.0-beta.2 dependencies: angel_framework: ">=0.0.0-dev < 0.1.0" mime: ">= 0.9.3 < 0.10.0"