From 27879f8b1994b746190ca2d8b8656b6f5bcb5611 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Mon, 31 Dec 2018 11:14:18 -0500 Subject: [PATCH] remove 1.x boilerplate --- CHANGELOG.md | 3 + lib/src/commands/init.dart | 16 ++-- lib/src/commands/rename.dart | 7 ++ sample-project/.dockerignore | 10 ++ sample-project/.gitignore | 90 ++++++++++++++++++ sample-project/.idea/angel.iml | 16 ++++ sample-project/.idea/misc.xml | 28 ++++++ sample-project/.idea/modules.xml | 8 ++ .../.idea/runConfigurations/dev_dart.xml | 8 ++ .../.idea/runConfigurations/prod_dart.xml | 11 +++ sample-project/.vscode/launch.json | 19 ++++ sample-project/.vscode/tasks.json | 27 ++++++ sample-project/Dockerfile | 14 +++ sample-project/LICENSE | 21 ++++ sample-project/README.md | 67 +++++++++++++ sample-project/analysis_options.yaml | 4 + sample-project/bin/dev.dart | 26 +++++ sample-project/bin/prod.dart | 4 + sample-project/config/default.yaml | 5 + sample-project/config/development.yaml | 2 + sample-project/config/production.yaml | 3 + sample-project/lib/sample_project.dart | 20 ++++ sample-project/lib/src/config/config.dart | 32 +++++++ .../lib/src/config/plugins/plugins.dart | 8 ++ .../src/routes/controllers/controllers.dart | 8 ++ sample-project/lib/src/routes/routes.dart | 61 ++++++++++++ sample-project/lib/src/services/services.dart | 14 +++ sample-project/pubspec.yaml | 20 ++++ sample-project/test/all_test.dart | 43 +++++++++ sample-project/views/error.jael | 5 + sample-project/views/hello.jael | 5 + sample-project/views/layout.jael | 17 ++++ sample-project/web/css/site.css | 27 ++++++ sample-project/web/images/favicon.png | Bin 0 -> 2853 bytes sample-project/web/robots.txt | 2 + 35 files changed, 643 insertions(+), 8 deletions(-) create mode 100644 sample-project/.dockerignore create mode 100644 sample-project/.gitignore create mode 100644 sample-project/.idea/angel.iml create mode 100644 sample-project/.idea/misc.xml create mode 100644 sample-project/.idea/modules.xml create mode 100644 sample-project/.idea/runConfigurations/dev_dart.xml create mode 100644 sample-project/.idea/runConfigurations/prod_dart.xml create mode 100644 sample-project/.vscode/launch.json create mode 100644 sample-project/.vscode/tasks.json create mode 100644 sample-project/Dockerfile create mode 100644 sample-project/LICENSE create mode 100644 sample-project/README.md create mode 100644 sample-project/analysis_options.yaml create mode 100644 sample-project/bin/dev.dart create mode 100644 sample-project/bin/prod.dart create mode 100644 sample-project/config/default.yaml create mode 100644 sample-project/config/development.yaml create mode 100644 sample-project/config/production.yaml create mode 100644 sample-project/lib/sample_project.dart create mode 100644 sample-project/lib/src/config/config.dart create mode 100644 sample-project/lib/src/config/plugins/plugins.dart create mode 100644 sample-project/lib/src/routes/controllers/controllers.dart create mode 100644 sample-project/lib/src/routes/routes.dart create mode 100644 sample-project/lib/src/services/services.dart create mode 100644 sample-project/pubspec.yaml create mode 100644 sample-project/test/all_test.dart create mode 100644 sample-project/views/error.jael create mode 100644 sample-project/views/hello.jael create mode 100644 sample-project/views/layout.jael create mode 100644 sample-project/web/css/site.css create mode 100644 sample-project/web/images/favicon.png create mode 100644 sample-project/web/robots.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a1c82e6..b3c221c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # 2.1.0 * Deprecate `angel install`. +* Rename projects using `snake_case`. +* `init` now fetches from `master`. +* Remove the `1.x` option. # 2.0.1 * `deploy systemd` now has an `--install` option, where you can immediately diff --git a/lib/src/commands/init.dart b/lib/src/commands/init.dart index a1da0f67..4766d390 100644 --- a/lib/src/commands/init.dart +++ b/lib/src/commands/init.dart @@ -4,6 +4,7 @@ import "package:args/command_runner.dart"; import 'package:io/ansi.dart'; import 'package:path/path.dart' as p; import 'package:prompts/prompts.dart' as prompts; +import 'package:recase/recase.dart'; import '../random_string.dart' as rs; import '../util.dart'; import 'key.dart'; @@ -45,6 +46,7 @@ class InitCommand extends Command { var name = p.basenameWithoutExtension( projectDir.absolute.uri.normalizePath().toFilePath()); + name = ReCase(name).snakeCase; print('Renaming project from "angel" to "$name"...'); await renamePubspec(projectDir, 'angel', name); await renameDartFiles(projectDir, 'angel', name); @@ -123,11 +125,10 @@ class InitCommand extends Command { } } - print('Choose a project type before continuing:'); - - //var boilerplate = basicBoilerplate; - var boilerplate = prompts.choose( - 'Choose a project type before continuing', boilerplates); + var boilerplate = basicBoilerplate; + // print('Choose a project type before continuing:'); + // var boilerplate = prompts.choose( + // 'Choose a project type before continuing', boilerplates); print( 'Cloning "${boilerplate.name}" boilerplate from "${boilerplate.url}"...'); @@ -227,8 +228,7 @@ const BoilerplateInfo ormBoilerplate = const BoilerplateInfo( const BoilerplateInfo basicBoilerplate = const BoilerplateInfo( 'Basic', 'Minimal starting point for Angel 2.x - A simple server with only a few additional packages.', - 'https://github.com/angel-dart/angel.git', - ref: '2.x'); + 'https://github.com/angel-dart/angel.git'); const BoilerplateInfo legacyBoilerplate = const BoilerplateInfo( 'Legacy', @@ -239,7 +239,7 @@ const BoilerplateInfo legacyBoilerplate = const BoilerplateInfo( const List boilerplates = const [ basicBoilerplate, - legacyBoilerplate, + //legacyBoilerplate, //ormBoilerplate, ]; diff --git a/lib/src/commands/rename.dart b/lib/src/commands/rename.dart index fee799eb..98a3752c 100644 --- a/lib/src/commands/rename.dart +++ b/lib/src/commands/rename.dart @@ -139,6 +139,13 @@ class RenamingVisitor extends RecursiveAstVisitor { return uri; } + @override + visitSimpleStringLiteral(SimpleStringLiteral node) { + if (node.value == '{{$oldName}}') { + replace[[node.value]] = newName; + } + } + @override visitExportDirective(ExportDirective ctx) { var uri = ctx.uri.stringValue, updated = updateUri(uri); diff --git a/sample-project/.dockerignore b/sample-project/.dockerignore new file mode 100644 index 00000000..faf23bd1 --- /dev/null +++ b/sample-project/.dockerignore @@ -0,0 +1,10 @@ +.dart_tool +.idea +.pub +.vscode +logs/ +test/ +build/ +.analysis-options +.packages +*.g.dart \ No newline at end of file diff --git a/sample-project/.gitignore b/sample-project/.gitignore new file mode 100644 index 00000000..d88b0dfb --- /dev/null +++ b/sample-project/.gitignore @@ -0,0 +1,90 @@ +# Created by .ignore support plugin (hsz.mobi) +### Dart template +# See https://www.dartlang.org/tools/private-files.html + +# source_gen +.dart_tool + +# Files and directories created by pub +.buildlog +.packages +.project +.pub/ +.scripts-bin/ +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 +### 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 + +### VSCode template +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +logs/ +*.pem +.DS_Store +server_log.txt diff --git a/sample-project/.idea/angel.iml b/sample-project/.idea/angel.iml new file mode 100644 index 00000000..eae13016 --- /dev/null +++ b/sample-project/.idea/angel.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample-project/.idea/misc.xml b/sample-project/.idea/misc.xml new file mode 100644 index 00000000..c65900a0 --- /dev/null +++ b/sample-project/.idea/misc.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + General + + + XPath + + + + + AngularJS + + + + + + \ No newline at end of file diff --git a/sample-project/.idea/modules.xml b/sample-project/.idea/modules.xml new file mode 100644 index 00000000..b0343846 --- /dev/null +++ b/sample-project/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/sample-project/.idea/runConfigurations/dev_dart.xml b/sample-project/.idea/runConfigurations/dev_dart.xml new file mode 100644 index 00000000..418187ff --- /dev/null +++ b/sample-project/.idea/runConfigurations/dev_dart.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/sample-project/.idea/runConfigurations/prod_dart.xml b/sample-project/.idea/runConfigurations/prod_dart.xml new file mode 100644 index 00000000..e93c56a5 --- /dev/null +++ b/sample-project/.idea/runConfigurations/prod_dart.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/sample-project/.vscode/launch.json b/sample-project/.vscode/launch.json new file mode 100644 index 00000000..ab26e089 --- /dev/null +++ b/sample-project/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Development Server", + "type": "dart", + "request": "launch", + "program": "${workspaceRoot}/bin/dev.dart", + "checkedMode": true + }, + { + "name": "Production Server", + "type": "dart", + "request": "launch", + "program": "${workspaceRoot}/bin/prod.dart", + "checkedMode": true + } + ] +} \ No newline at end of file diff --git a/sample-project/.vscode/tasks.json b/sample-project/.vscode/tasks.json new file mode 100644 index 00000000..0479cc0b --- /dev/null +++ b/sample-project/.vscode/tasks.json @@ -0,0 +1,27 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "0.1.0", + "command": "pub", + "isShellCommand": true, + "echoCommand": true, + "showOutput": "always", + "tasks": [ + { + "taskName": "pub:build", + "suppressTaskName": true, + "args": [ + "build" + ] + }, + { + "taskName": "pub:serve", + "showOutput": "silent", + "suppressTaskName": true, + "isBackground": true, + "args": [ + "serve" + ] + } + ] +} \ No newline at end of file diff --git a/sample-project/Dockerfile b/sample-project/Dockerfile new file mode 100644 index 00000000..f9056deb --- /dev/null +++ b/sample-project/Dockerfile @@ -0,0 +1,14 @@ +FROM google/dart:2.0 + +COPY ./ ./ + +# Install dependencies, pre-build +RUN pub get + +# Optionally build generaed sources. +# RUN pub run build_runner build + +# Set environment, start server +ENV ANGEL_ENV=production +EXPOSE 3000 +CMD dart bin/prod.dart \ No newline at end of file diff --git a/sample-project/LICENSE b/sample-project/LICENSE new file mode 100644 index 00000000..52a1469a --- /dev/null +++ b/sample-project/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/sample-project/README.md b/sample-project/README.md new file mode 100644 index 00000000..aff56f62 --- /dev/null +++ b/sample-project/README.md @@ -0,0 +1,67 @@ +[![The Angel Framework](https://angel-dart.github.io/assets/images/logo.png)](https://angel-dart.github.io) + +[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/angel_dart/discussion) +[![Pub](https://img.shields.io/pub/v/angel_framework.svg)](https://pub.dartlang.org/packages/angel_framework) +[![Build status](https://travis-ci.org/angel-dart/framework.svg?branch=master)](https://travis-ci.org/angel-dart/framework) +![License](https://img.shields.io/github/license/angel-dart/framework.svg) + +**A batteries-included, full-stack Web server framework for Dart.** + +----- + +[Wiki (in-depth documentation)](https://github.com/angel-dart/angel/wiki) + +[API Documentation](http://www.dartdocs.org/documentation/angel_common/latest) + +[Roadmap](https://github.com/angel-dart/roadmap/blob/master/ROADMAP.md) + +[File an Issue](https://github.com/angel-dart/roadmap/issues) + +[Awesome Angel :fire:](https://github.com/angel-dart/awesome-angel) + + + +Like what you see? Please lend us a star! :star: + +## Newest Tutorials +* [Dependency Injection Patterns with Angel 2](https://thosakwe.com/dependency-injection-patterns-in-angel-2/) +* [Angel 2.0.0 is Almost Here - What it Means for You](https://thosakwe.com/new-features-coming-to-angel-in-version-2-0-0/) +* [GraphQL is coming to Angel (and Dart)](https://thosakwe.com/graphql-is-coming-to-angel-and-dart/) + +## Installation & Setup +*Having errors with a fresh Angel installation? See [here](https://angel-dart.gitbook.io/angel/the-basics/installation) for help.* + +Once you have [Dart](https://www.dartlang.org/) installed, bootstrapping a project is as simple as running a few shell commands: + +Install the [Angel CLI](https://github.com/angel-dart/cli): + +```bash +pub global activate angel_cli +``` + +Bootstrap a project: + +```bash +angel init hello +``` + +You can even have your server run and be *hot-reloaded* on file changes: + +```bash +dart --observe bin/dev.dart +``` + +Next, check out the [detailed documentation](https://angel-dart.gitbook.io/angel) to learn to flesh out your project. + +## Features +With features like the following, Angel is the all-in-one framework you should choose to build your next project: +* [Advanced, Modular Routing](https://github.com/angel-dart/route) +* [Middleware](https://angel-dart.gitbook.io/angel/the-basics/middleware) +* [Dependency Injection](https://angel-dart.gitbook.io/angel/the-basics/dependency-injection) +* [Strongly-typed ORM](https://github.com/angel-dart/orm) +* And [much more](https://github.com/angel-dart)... + +## Basic Example +Examples and complete projects can be found here: + +https://github.com/angel-dart/examples-v2 diff --git a/sample-project/analysis_options.yaml b/sample-project/analysis_options.yaml new file mode 100644 index 00000000..a4f33350 --- /dev/null +++ b/sample-project/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:pedantic/analysis_options.yaml +analyzer: + strong-mode: + implicit-casts: false diff --git a/sample-project/bin/dev.dart b/sample-project/bin/dev.dart new file mode 100644 index 00000000..9347bc87 --- /dev/null +++ b/sample-project/bin/dev.dart @@ -0,0 +1,26 @@ +import 'dart:io'; +import 'package:sample_project/src/pretty_logging.dart'; +import 'package:sample_project/sample_project.dart'; +import 'package:angel_container/mirrors.dart'; +import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_hot/angel_hot.dart'; +import 'package:logging/logging.dart'; + +main() async { + // Watch the config/ and web/ directories for changes, and hot-reload the server. + var hot = new HotReloader(() async { + var app = new Angel(reflector: MirrorsReflector()); + await app.configure(configureServer); + hierarchicalLoggingEnabled = true; + app.logger = new Logger('angel'); + var sub = app.logger.onRecord.listen(prettyLog); + app.shutdownHooks.add((_) => sub.cancel()); + return app; + }, [ + new Directory('config'), + new Directory('lib'), + ]); + + var server = await hot.startServer('127.0.0.1', 3000); + print('Listening at http://${server.address.address}:${server.port}'); +} diff --git a/sample-project/bin/prod.dart b/sample-project/bin/prod.dart new file mode 100644 index 00000000..fdaf2e12 --- /dev/null +++ b/sample-project/bin/prod.dart @@ -0,0 +1,4 @@ +import 'package:sample_project/sample_project.dart'; +import 'package:angel_production/angel_production.dart'; + +main(List args) => Runner('angel', configureServer).run(args); diff --git a/sample-project/config/default.yaml b/sample-project/config/default.yaml new file mode 100644 index 00000000..8f6fea0d --- /dev/null +++ b/sample-project/config/default.yaml @@ -0,0 +1,5 @@ +# Default server configuration. +host: 127.0.0.1 +mongo_db: mongodb://localhost:27017/angel +port: 3000 +jwt_secret: "IIeewWFKTdCJIT5zLh09J2gFKmfpgh0J" \ No newline at end of file diff --git a/sample-project/config/development.yaml b/sample-project/config/development.yaml new file mode 100644 index 00000000..4bed71e2 --- /dev/null +++ b/sample-project/config/development.yaml @@ -0,0 +1,2 @@ +# Development-only server configuration. +debug: true \ No newline at end of file diff --git a/sample-project/config/production.yaml b/sample-project/config/production.yaml new file mode 100644 index 00000000..a6ff83f2 --- /dev/null +++ b/sample-project/config/production.yaml @@ -0,0 +1,3 @@ +# Production-only server configuration +debug: false +jwt_secret: "DJ3JnBDBS6UcnbAGwPQb3m7YWxja7KLZ" \ No newline at end of file diff --git a/sample-project/lib/sample_project.dart b/sample-project/lib/sample_project.dart new file mode 100644 index 00000000..0da05718 --- /dev/null +++ b/sample-project/lib/sample_project.dart @@ -0,0 +1,20 @@ +library sample_project; + +import 'dart:async'; +import 'package:angel_framework/angel_framework.dart'; +import 'package:file/local.dart'; +import 'src/config/config.dart' as configuration; +import 'src/routes/routes.dart' as routes; +import 'src/services/services.dart' as services; + +/// Configures the server instance. +Future configureServer(Angel app) async { + // Grab a handle to the file system, so that we can do things like + // serve static files. + var fs = const LocalFileSystem(); + + // Set up our application, using the plug-ins defined with this project. + await app.configure(configuration.configureServer(fs)); + await app.configure(services.configureServer); + await app.configure(routes.configureServer(fs)); +} diff --git a/sample-project/lib/src/config/config.dart b/sample-project/lib/src/config/config.dart new file mode 100644 index 00000000..e7b8c562 --- /dev/null +++ b/sample-project/lib/src/config/config.dart @@ -0,0 +1,32 @@ +library sample_project.src.config; + +import 'package:angel_configuration/angel_configuration.dart'; +import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_jael/angel_jael.dart'; +import 'package:file/file.dart'; +import 'plugins/plugins.dart' as plugins; + +/// This is a perfect place to include configuration and load plug-ins. +AngelConfigurer configureServer(FileSystem fileSystem) { + return (Angel app) async { + // Load configuration from the `config/` directory. + // + // See: https://github.com/angel-dart/configuration + await app.configure(configuration(fileSystem)); + + // Configure our application to render Jael templates from the `views/` directory. + // + // See: https://github.com/angel-dart/jael + await app.configure(jael(fileSystem.directory('views'))); + + // Apply another plug-ins, i.e. ones that *you* have written. + // + // Typically, the plugins in `lib/src/config/plugins/plugins.dart` are plug-ins + // that add functionality specific to your application. + // + // If you write a plug-in that you plan to use again, or are + // using one created by the community, include it in + // `lib/src/config/config.dart`. + await plugins.configureServer(app); + }; +} diff --git a/sample-project/lib/src/config/plugins/plugins.dart b/sample-project/lib/src/config/plugins/plugins.dart new file mode 100644 index 00000000..5e6d9ea3 --- /dev/null +++ b/sample-project/lib/src/config/plugins/plugins.dart @@ -0,0 +1,8 @@ +library sample_project.src.config.plugins; + +import 'dart:async'; +import 'package:angel_framework/angel_framework.dart'; + +Future configureServer(Angel app) async { + // Include any plugins you have made here. +} diff --git a/sample-project/lib/src/routes/controllers/controllers.dart b/sample-project/lib/src/routes/controllers/controllers.dart new file mode 100644 index 00000000..1f10cc1a --- /dev/null +++ b/sample-project/lib/src/routes/controllers/controllers.dart @@ -0,0 +1,8 @@ +library sample_project.src.routes.controllers; + +import 'dart:async'; +import 'package:angel_framework/angel_framework.dart'; + +Future configureServer(Angel app) async { + /// Controllers will not function unless wired to the application! +} diff --git a/sample-project/lib/src/routes/routes.dart b/sample-project/lib/src/routes/routes.dart new file mode 100644 index 00000000..8953bd40 --- /dev/null +++ b/sample-project/lib/src/routes/routes.dart @@ -0,0 +1,61 @@ +library sample_project.src.routes; + +import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_static/angel_static.dart'; +import 'package:file/file.dart'; +import 'controllers/controllers.dart' as controllers; + +/// Put your app routes here! +/// +/// See the wiki for information about routing, requests, and responses: +/// * https://github.com/angel-dart/angel/wiki/Basic-Routing +/// * https://github.com/angel-dart/angel/wiki/Requests-&-Responses +AngelConfigurer configureServer(FileSystem fileSystem) { + return (Angel app) async { + // Typically, you want to mount controllers first, after any global middleware. + await app.configure(controllers.configureServer); + + // Render `views/hello.jl` when a user visits the application root. + app.get('/', (req, res) => res.render('hello')); + + // Mount static server at web in development. + // The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers. + // + // In production, however, prefer serving static files through NGINX or a + // similar reverse proxy. + // + // Read the following two sources for documentation: + // * https://medium.com/the-angel-framework/serving-static-files-with-the-angel-framework-2ddc7a2b84ae + // * https://github.com/angel-dart/static + if (!app.isProduction) { + var vDir = VirtualDirectory( + app, + fileSystem, + source: fileSystem.directory('web'), + ); + app.fallback(vDir.handleRequest); + } + + // Throw a 404 if no route matched the request. + app.fallback((req, res) => throw AngelHttpException.notFound()); + + // Set our application up to handle different errors. + // + // Read the following for documentation: + // * https://github.com/angel-dart/angel/wiki/Error-Handling + + var oldErrorHandler = app.errorHandler; + app.errorHandler = (e, req, res) async { + if (!req.accepts('text/html')) + return await oldErrorHandler(e, req, res); + else { + if (e.statusCode == 404) { + return await res + .render('error', {'message': 'No file exists at ${req.uri}.'}); + } + + return await res.render('error', {'message': e.message}); + } + }; + }; +} diff --git a/sample-project/lib/src/services/services.dart b/sample-project/lib/src/services/services.dart new file mode 100644 index 00000000..68f1123e --- /dev/null +++ b/sample-project/lib/src/services/services.dart @@ -0,0 +1,14 @@ +library sample_project.services; + +import 'dart:async'; +import 'package:angel_framework/angel_framework.dart'; + +/// Configure our application to use *services*. +/// Services must be wired to the app via `app.use`. +/// +/// They provide many benefits, such as instant REST API generation, +/// and respond to both REST and WebSockets. +/// +/// Read more here: +/// https://github.com/angel-dart/angel/wiki/Service-Basics +Future configureServer(Angel app) async {} diff --git a/sample-project/pubspec.yaml b/sample-project/pubspec.yaml new file mode 100644 index 00000000..a1c5aa38 --- /dev/null +++ b/sample-project/pubspec.yaml @@ -0,0 +1,20 @@ +name: sample_project +description: An app that's going to be amazing pretty soon. +publish_to: none # Ensure we don't accidentally publish our private code! ;) +environment: + sdk: '>=2.0.0-dev <3.0.0' +homepage: https://github.com/angel-dart/angel +dependencies: + angel_auth: ^2.0.0-alpha # Supports stateless authentication via JWT + angel_configuration: ^2.0.0 # Loads application configuration, along with support for .env files. + angel_framework: ^2.0.0-alpha # The core server library. + angel_jael: ^2.0.0 # Server-side templating engine + angel_production: ^1.0.0-alpha + angel_static: ^2.0.0-alpha # Static file server + angel_validate: ^2.0.0-alpha # Allows for validation of input data +dev_dependencies: + angel_hot: ^2.0.0 # Hot-reloading support. :) + angel_test: ^2.0.0-alpha # Utilities for testing Angel servers. + io: ^0.3.2 + pedantic: ^1.0.0 + test: ^1.0.0 diff --git a/sample-project/test/all_test.dart b/sample-project/test/all_test.dart new file mode 100644 index 00000000..06bec6e5 --- /dev/null +++ b/sample-project/test/all_test.dart @@ -0,0 +1,43 @@ +import 'package:sample_project/sample_project.dart'; +import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_test/angel_test.dart'; +import 'package:test/test.dart'; + +// Angel also includes facilities to make testing easier. +// +// `package:angel_test` ships a client that can test +// both plain HTTP and WebSockets. +// +// Tests do not require your server to actually be mounted on a port, +// so they will run faster than they would in other frameworks, where you +// would have to first bind a socket, and then account for network latency. +// +// See the documentation here: +// https://github.com/angel-dart/test +// +// If you are unfamiliar with Dart's advanced testing library, you can read up +// here: +// https://github.com/dart-lang/test + +main() async { + TestClient client; + + setUp(() async { + var app = Angel(); + await app.configure(configureServer); + + client = await connectTo(app); + }); + + tearDown(() async { + await client.close(); + }); + + test('index returns 200', () async { + // Request a resource at the given path. + var response = await client.get('/'); + + // Expect a 200 response. + expect(response, hasStatus(200)); + }); +} diff --git a/sample-project/views/error.jael b/sample-project/views/error.jael new file mode 100644 index 00000000..1e93df46 --- /dev/null +++ b/sample-project/views/error.jael @@ -0,0 +1,5 @@ + + +
{{ message }}
+
+
\ No newline at end of file diff --git a/sample-project/views/hello.jael b/sample-project/views/hello.jael new file mode 100644 index 00000000..7ca6b8af --- /dev/null +++ b/sample-project/views/hello.jael @@ -0,0 +1,5 @@ + + +
Angel
+
+
\ No newline at end of file diff --git a/sample-project/views/layout.jael b/sample-project/views/layout.jael new file mode 100644 index 00000000..ea0714bc --- /dev/null +++ b/sample-project/views/layout.jael @@ -0,0 +1,17 @@ + + + + {{ title ?? 'Angel' }} + + + + + + +
+
+ +
+
+ + \ No newline at end of file diff --git a/sample-project/web/css/site.css b/sample-project/web/css/site.css new file mode 100644 index 00000000..9e40b8de --- /dev/null +++ b/sample-project/web/css/site.css @@ -0,0 +1,27 @@ +html, body { + height: 100%; +} + +body { + margin: 0; + padding: 0; + width: 100%; + display: table; + font-weight: 100; + font-family: 'Lato', sans-serif; +} + +.container { + text-align: center; + display: table-cell; + vertical-align: middle; +} + +.content { + text-align: center; + display: inline-block; +} + +.title { + font-size: 96px; +} \ No newline at end of file diff --git a/sample-project/web/images/favicon.png b/sample-project/web/images/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..8be3ad791e165bad029dcf6f9c23c6aeb1c66fc9 GIT binary patch literal 2853 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 literal 0 HcmV?d00001 diff --git a/sample-project/web/robots.txt b/sample-project/web/robots.txt new file mode 100644 index 00000000..f328961c --- /dev/null +++ b/sample-project/web/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: /admin \ No newline at end of file