This commit is contained in:
thosakwe 2016-02-28 08:11:17 -05:00
commit 31607686be
7 changed files with 150 additions and 0 deletions

65
.gitignore vendored Normal file
View file

@ -0,0 +1,65 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
*.iml
## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:
# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml
# Gradle:
# .idea/gradle.xml
# .idea/libraries
# Mongo Explorer plugin:
# .idea/mongoSettings.xml
## File-based project format:
*.ipr
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
### Dart template
# Dont commit the following directories created by pub.
.buildlog
.pub/
build/
packages
.packages
# Or the files created by dart2js.
*.dart.js
*.js_
*.js.deps
*.js.map
# Include when developing application packages.
pubspec.lock

4
lib/angel_framework.dart Normal file
View file

@ -0,0 +1,4 @@
/// A controller-based MVC + WebSocket framework in Dart.
library angel_framework;
export 'src/http/http.dart';

11
lib/src/http/http.dart Normal file
View file

@ -0,0 +1,11 @@
/// HTTP logic
library angel_framework.http;
import 'dart:async';
import 'dart:io';
import 'package:json_god/json_god.dart';
import 'package:route/server.dart';
part 'route.dart';
part 'routable.dart';
part 'server.dart';

View file

@ -0,0 +1,10 @@
part of angel_framework.http;
/// A routable server that can handle dynamic requests.
class Routable {
/// Additional filters to be run on designated requests.
Map <String, Object> middleware = {};
/// Dynamic request paths that this server will respond to.
Map <Route, Object> routes = {};
}

14
lib/src/http/route.dart Normal file
View file

@ -0,0 +1,14 @@
part of angel_framework.http;
class Route {
Pattern matcher;
String method;
Route(String method, Pattern path, [List handlers]) {
this.method = method;
if (path is RegExp) this.matcher = path;
else this.matcher = new RegExp('^' +
path.toString().replaceAll(new RegExp('\/'), r'\/').replaceAll(
new RegExp(':[a-zA-Z_]+'), '([^\/]+)') + r'$');
}
}

39
lib/src/http/server.dart Normal file
View file

@ -0,0 +1,39 @@
part of angel_framework.http;
/// A function that binds
typedef Future<HttpServer> ServerGenerator(InternetAddress address, int port);
/// A powerful real-time/REST/MVC server class.
class Angel extends Routable {
ServerGenerator _serverGenerator;
_startServer(InternetAddress address, int port) async {
var server = await _serverGenerator(
address ?? InternetAddress.LOOPBACK_IP_V4, port);
var router = new Router(server);
this.routes.forEach((Route route, value) {
router.serve(route.matcher, method: route.method).listen((
HttpRequest request) {
});
});
}
/// Starts the server.
void listen({InternetAddress address, int port: 3000}) {
runZoned(() async {
await _startServer(address, port);
}, onError: onError);
}
/// Handles a server error.
void onError(e, [StackTrace stackTrace]) {
}
Angel() {}
/// Creates an HTTPS server.
Angel.secure() {}
}

7
pubspec.yaml Normal file
View file

@ -0,0 +1,7 @@
name: angel_framework
version: 0.0.1-dev
description: Core libraries for the Angel framework.
author: Tobe O <thosakwe@gmail.com>
dependencies:
json_god: any
route: any