From 77af2aa8e4c42f9e9dfe3df23e974d14b16d932f Mon Sep 17 00:00:00 2001 From: regiostech Date: Thu, 21 Apr 2016 22:56:21 -0400 Subject: [PATCH] :) --- .gitignore | 112 +++++++++++++++++++++++ .idea/runConfigurations/Start_Server.xml | 6 ++ .idea/vcs.xml | 6 ++ LICENSE | 21 +++++ bin/server.dart | 20 ++++ config/default.yaml | 2 + config/development.yaml | 2 + config/production.yaml | 2 + lib/angel.dart | 14 +++ lib/src/config/config.dart | 14 +++ lib/src/config/routes.dart | 20 ++++ pubspec.yaml | 14 +++ views/404.mustache | 50 ++++++++++ views/hello.mustache | 45 +++++++++ web/robots.txt | 2 + 15 files changed, 330 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/runConfigurations/Start_Server.xml create mode 100644 .idea/vcs.xml create mode 100644 LICENSE create mode 100644 bin/server.dart create mode 100644 config/default.yaml create mode 100644 config/development.yaml create mode 100644 config/production.yaml create mode 100644 lib/angel.dart create mode 100644 lib/src/config/config.dart create mode 100644 lib/src/config/routes.dart create mode 100644 pubspec.yaml create mode 100644 views/404.mustache create mode 100644 views/hello.mustache create mode 100644 web/robots.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c74d02 --- /dev/null +++ b/.gitignore @@ -0,0 +1,112 @@ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.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: +*.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 +fabric.properties +### Dart template +# See https://www.dartlang.org/tools/private-files.html + +# Files and directories created by pub +.buildlog +.packages +.project +.pub/ +build/ +**/packages/ + +# Files created by dart2js +# (Most Dart developers will use pub build to compile Dart, use/modify these +# rules if you intend to use dart2js directly +# Convention is to use extension '.dart.js' for Dart compiled to Javascript to +# differentiate from explicit Javascript files) +*.dart.js +*.part.js +*.js.deps +*.js.map +*.info.json + +# Directory created by dartdoc +doc/api/ + +# Don't commit pubspec lock file +# (Library packages only! Remove pattern if developing an application package) +pubspec.lock +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: + +# Sensitive or high-churn files: + +# Gradle: + +# Mongo Explorer plugin: + +## File-based project format: + +## Plugin-specific files: + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) +### Dart template +# See https://www.dartlang.org/tools/private-files.html + +# Files and directories created by pub + +# Files created by dart2js +# (Most Dart developers will use pub build to compile Dart, use/modify these +# rules if you intend to use dart2js directly +# Convention is to use extension '.dart.js' for Dart compiled to Javascript to +# differentiate from explicit Javascript files) + +# Directory created by dartdoc + +# Don't commit pubspec lock file +# (Library packages only! Remove pattern if developing an application package) diff --git a/.idea/runConfigurations/Start_Server.xml b/.idea/runConfigurations/Start_Server.xml new file mode 100644 index 0000000..4b1dfdc --- /dev/null +++ b/.idea/runConfigurations/Start_Server.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..52a1469 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 angel-dart + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/bin/server.dart b/bin/server.dart new file mode 100644 index 0000000..bd213ea --- /dev/null +++ b/bin/server.dart @@ -0,0 +1,20 @@ +import 'dart:async'; +import 'dart:io'; +import 'package:angel/angel.dart'; +import 'package:angel_framework/angel_framework.dart'; + +main() async { + Angel app = createServer(); + + runZoned(() async { + await app.startServer( + new InternetAddress(app.properties['host']), app.properties['port']); + print("Angel server listening on ${app.httpServer.address.host}:${app + .httpServer.port}"); + }, onError: (error, [StackTrace stackTrace]) { + stderr.writeln("Unhandled error occurred: $error"); + if (stackTrace != null) { + stderr.writeln(stackTrace); + } + }); +} \ No newline at end of file diff --git a/config/default.yaml b/config/default.yaml new file mode 100644 index 0000000..0e200f6 --- /dev/null +++ b/config/default.yaml @@ -0,0 +1,2 @@ +# Default server configuration. +host: 127.0.0.1 \ No newline at end of file diff --git a/config/development.yaml b/config/development.yaml new file mode 100644 index 0000000..bcfffb6 --- /dev/null +++ b/config/development.yaml @@ -0,0 +1,2 @@ +# Development-only server configuration. +port: 3000 \ No newline at end of file diff --git a/config/production.yaml b/config/production.yaml new file mode 100644 index 0000000..ef49edc --- /dev/null +++ b/config/production.yaml @@ -0,0 +1,2 @@ +# Production-only server configuration +port: 80 \ No newline at end of file diff --git a/lib/angel.dart b/lib/angel.dart new file mode 100644 index 0000000..745e172 --- /dev/null +++ b/lib/angel.dart @@ -0,0 +1,14 @@ +/// Your very own web application! +library angel; + +import 'package:angel_framework/angel_framework.dart'; +import 'src/config/config.dart' show configureServer; + +/// Creates and configures the server instance. +Angel createServer() { + Angel app = new Angel(); + + app.configure(configureServer); + + return app; +} \ No newline at end of file diff --git a/lib/src/config/config.dart b/lib/src/config/config.dart new file mode 100644 index 0000000..5ae1efd --- /dev/null +++ b/lib/src/config/config.dart @@ -0,0 +1,14 @@ +/// Configuration for this Angel instance. +library angel.config; + +import 'dart:io'; +import 'package:angel_configuration/angel_configuration.dart'; +import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_mustache/angel_mustache.dart'; +import 'routes.dart'; + +configureServer(Angel app) { + app.configure(loadConfigurationFile()); + app.configure(mustache(new Directory('views'))); + app.configure(configureRoutes); +} \ No newline at end of file diff --git a/lib/src/config/routes.dart b/lib/src/config/routes.dart new file mode 100644 index 0000000..aedf4c1 --- /dev/null +++ b/lib/src/config/routes.dart @@ -0,0 +1,20 @@ +/// This app's route configuration. +library angel.routes; + +import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_static/angel_static.dart'; + +/// Put your app routes here! +configureRoutes(Angel app) { + app.get('/', (req, ResponseContext res) => res.render('hello')); + app.get('*', serveStatic()); + + app.on404 = (RequestContext req, ResponseContext res) async { + res.willCloseItself = true; + res.status(404); + res.header('Content-Type', 'text/html'); + res.underlyingResponse.write( + await app.viewGenerator('404', {'path': req.path})); + await res.underlyingResponse.close(); + }; +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..bd14427 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,14 @@ +name: angel +description: An easily-extensible web server framework in Dart. +version: 0.0.0-dev.0 +author: thosakwe +homepage: https://github.com/angel-dart/angel +dependencies: + angel_configuration: ">= 1.0.0-dev < 2.0.0" + angel_framework: ">=0.0.0-dev < 0.1.0" + angel_mustache: ">= 1.0.0-dev < 2.0.0" + angel_static: ">= 1.0.0-beta.1 < 1.1.0" + json_god: ">= 1.0.0 < 2.0.0" +dev_dependencies: + http: ">= 0.11.3 < 0.12.0" + test: ">= 0.12.13 < 0.13.0" \ No newline at end of file diff --git a/views/404.mustache b/views/404.mustache new file mode 100644 index 0000000..3896919 --- /dev/null +++ b/views/404.mustache @@ -0,0 +1,50 @@ + + + + 404 Not Found + + + + + + +
+
+
404 Not Found
+
No file was found at "{{path}}".
+
+
+ + \ No newline at end of file diff --git a/views/hello.mustache b/views/hello.mustache new file mode 100644 index 0000000..530c4be --- /dev/null +++ b/views/hello.mustache @@ -0,0 +1,45 @@ + + + + Angel + + + + + + +
+
+
Angel
+
+
+ + \ No newline at end of file diff --git a/web/robots.txt b/web/robots.txt new file mode 100644 index 0000000..f328961 --- /dev/null +++ b/web/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: /admin \ No newline at end of file