Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from sethladd/master
More complex server example, better README
- Loading branch information
Showing
10 changed files
with
198 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,155 @@ | ||
# Heroku Buildpack: Dart | ||
|
||
This is a Heroku buildpack for [Dart](http://www.dartlang.org/). | ||
This is a Heroku buildpack for [Dart][]. | ||
|
||
Installation of packages through [pub](http://pub.dartlang.org/) is supported. | ||
## Features | ||
|
||
A Dart build script (build.dart) will be executed if found. | ||
* Runs Dart VM as a server in Heroku's cloud | ||
* Installs packages with [pub][] | ||
* Builds the client app with [pub build][build] | ||
|
||
*NOTE*: The current official builds of Dart SDK do not support Heroku, due to | ||
mismatched glibc versions. You need to provide your own .tar.gz of Dart SDK, | ||
compiled for Ubuntu 10.04 (Heroku's Cedar stack). Get [instructions for | ||
building Dart for Ubuntu 10.04][instructions]. | ||
compiled for Ubuntu 10.04 (Heroku's Cedar stack). Get | ||
[instructions for building Dart for Ubuntu 10.04][buildforubuntu]. | ||
|
||
## Getting Started | ||
|
||
(These instructions assume you have the | ||
[heroku tools](https://toolbelt.heroku.com/) and | ||
[git](http://git-scm.com/) installed, and that you have a heroku | ||
account.) | ||
|
||
Create a Heroku app with the _cedar_ stack, specify both this | ||
buildpack and a URL to a Dart SDK compiled for Ubuntu 10.04. | ||
|
||
```bash | ||
$> heroku create myapp_name -s cedar | ||
$> git clone https://github.com/igrigorik/heroku-buildpack-dart.git | ||
$> mkdir myfirstdartappforheroku | ||
$> cp -R heroku-buildpack-dart/test-app/* myfirstdartappforheroku | ||
$> cd myfirstdartappforheroku | ||
$> git init | ||
$> git add -A . | ||
$> git commit -am "first commit" | ||
$> heroku create myfirstdartappforheroku -s cedar | ||
$> heroku ps:scale web=1 | ||
$> heroku labs:enable user-env-compile | ||
$> heroku config:set DART_SDK_URL=<archive url> | ||
$> heroku config:add BUILDPACK_URL=https://github.com/igrigorik/heroku-buildpack-dart.git | ||
``` | ||
|
||
# create your app, see test-app for an example | ||
Push the app to Heroku. Learn more about [deploying to Heroku with git][deploy]. | ||
|
||
```bash | ||
$> git push heroku master | ||
``` | ||
|
||
Example output from a `git push`: | ||
|
||
Counting objects: 7, done. | ||
```bash | ||
Initializing repository, done. | ||
Counting objects: 11, done. | ||
Delta compression using up to 8 threads. | ||
Compressing objects: 100% (4/4), done. | ||
Writing objects: 100% (7/7), 1008 bytes, done. | ||
Total 7 (delta 0), reused 0 (delta 0) | ||
Compressing objects: 100% (11/11), done. | ||
Writing objects: 100% (11/11), 2.27 KiB | 0 bytes/s, done. | ||
Total 11 (delta 0), reused 0 (delta 0) | ||
|
||
-----> Fetching custom git buildpack... done | ||
-----> Dart app detected | ||
-----> Welcome, this machine is: Linux 2704a4f7-0e7d-4eef-83e7-39833c31aa74 3.8.11-ec2 #1 SMP Fri May 3 09:11:15 UTC 2013 x86_64 GNU/Linux | ||
-----> Installing Dart VM via URL <YOUR ARCHIVE URL> | ||
-----> Welcome, this machine is: Linux 4d4ac1e0-412c-4734-9a68-0e0002f669cf 3.8.11-ec2 #1 SMP Fri May 3 09:11:15 UTC 2013 x86_64 GNU/Linux | ||
-----> Installing Dart VM via URL https://www.dropbox.com/s/y1eq2rkc8j7nyek/dart-sdk-v1.1.0-dev.4.0.tar.gz | ||
% Total % Received % Xferd Average Speed Time Time Time Current | ||
Dload Upload Total Spent Left Speed | ||
100 10.2M 100 10.2M 0 0 4122k 0 0:00:02 0:00:02 --:--:-- 4150k | ||
100 10.3M 100 10.3M 0 0 5822k 0 0:00:01 0:00:01 --:--:-- 13.4M | ||
-----> Copy Dart binaries to app root | ||
-----> Dart cmd found at -rwx------ 1 u54109 54109 10539520 Oct 27 01:49 /app/dart-sdk/bin/dart | ||
Dart VM version: 0.8.6.0_r29156_sethladd (Sat Oct 26 18:36:05 2013) on "linux_x64" | ||
-----> Dart cmd found at -rwx------ 1 u13180 13180 10064032 Dec 22 19:23 /app/dart-sdk/bin/dart | ||
Dart VM version: 1.1.0-dev.4.0 (Mon Dec 16 12:29:42 2013) on "linux_x64" | ||
-----> Dart reports version: | ||
-----> Install packages | ||
*** Found pubspec.yaml in . | ||
Resolving dependencies............ | ||
Downloading route 0.4.5+1 from hosted... | ||
Downloading path 0.8.6 from hosted... | ||
Downloading http_server 0.8.6 from hosted... | ||
Downloading browser 0.8.6 from hosted... | ||
Downloading logging 0.8.6 from hosted... | ||
Downloading mime 0.8.6 from hosted... | ||
*** Found pubspec.yaml in /tmp/build_c4247abc-3094-495f-870d-4e72fe1f1f36/. | ||
*** Running pub get | ||
Resolving dependencies....... | ||
Downloading browser 0.9.0... | ||
Downloading http_server 0.9.1... | ||
Downloading mime 0.9.0... | ||
Downloading path 1.0.0... | ||
Got dependencies! | ||
*** Running pub build | ||
Building basic_http_server....... | ||
[Info in Dart2JS]: | ||
Took 0:00:06.587561 to compile basic_http_server|web/index.dart. | ||
Built 8 files! | ||
total | ||
-----> Discovering process types | ||
Procfile declares types -> web | ||
Procfile declares types -> (none) | ||
|
||
-----> Compiled slug size: 10.3MB | ||
-----> Launching... done, v7 | ||
http://dart-server-test.herokuapp.com deployed to Heroku | ||
-----> Compressing... done, 10.5MB | ||
-----> Launching... done, v6 | ||
http://myfirstdartapp2.herokuapp.com deployed to Heroku | ||
|
||
To git@heroku.com:dart-server-test.git | ||
To git@heroku.com:myfirstdartapp2.git | ||
* [new branch] master -> master | ||
``` | ||
|
||
## Configuration | ||
|
||
$> curl http://myapp_name.herokuapp.com/ | ||
### Enable ENV Variables | ||
|
||
You must tell Heroku to pass environment variables through to your app. | ||
|
||
```bash | ||
$> heroku labs:enable user-env-compile | ||
``` | ||
|
||
More info on that can be found in | ||
[Heroku's Devcenter: Heroku Labs: user-env-compile][envcompile]. | ||
|
||
### Location of Dart SDK | ||
|
||
You must specify a URL that points to a .tar.gz file of the Dart SDK. The SDK | ||
must be built for a Ubuntu 10.04 environment. | ||
|
||
```bash | ||
$> heroku config:set DART_SDK_URL=<archive url> | ||
``` | ||
|
||
There are [instructions for building Dart SDK for Ubuntu 10.04][buildforubuntu]. | ||
|
||
### Specifying the script | ||
|
||
The `Procfile` defines the file to run when the application starts. We | ||
recommend to put the server script into your application's `bin/` directory. | ||
|
||
The sample app's `Procfile` looks like: | ||
|
||
``` | ||
web: ./dart-sdk/bin/dart bin/basic_http_server.dart | ||
``` | ||
|
||
Learn more about | ||
|
||
## Example | ||
|
||
See `test-app` directory for the world simplest Dart web app running on Heroku: [http://dart-server-test.herokuapp.com/](http://dart-server-test.herokuapp.com/) | ||
See `test-app` directory for the world simplest Dart web app running on | ||
Heroku: [dartvm.herokuapp.com](http://dartvm.herokuapp.com/) | ||
|
||
## Learning more | ||
|
||
Dart VM can access files, directories, sockets, HTTP, web sockets, SSL, and | ||
more. See the [dart:io library][io] for core functionality. | ||
|
||
Dart's package repository, [pub][], hosts lots of options for more | ||
functionality, such as database drivers, HTTP server frameworks, templates, | ||
and more. | ||
|
||
## License | ||
|
||
The MIT License - Copyright (c) 2012 Ilya Grigorik | ||
|
||
|
||
[instructions]: https://code.google.com/p/dart/wiki/BuildDartSDKOnUbuntu10_04 | ||
[io]: https://api.dartlang.org/docs/channels/stable/latest/dart_io.html | ||
[pub]: http://pub.dartlang.org | ||
[dart]: https://www.dartlang.org | ||
[build]: http://pub.dartlang.org/doc/pub-build.html | ||
[example]: https://github.com/igrigorik/heroku-buildpack-dart/tree/master/test-app | ||
[deploy]: https://devcenter.heroku.com/articles/git | ||
[envcompile]: https://devcenter.heroku.com/articles/labs-user-env-compile | ||
[buildforubuntu]: https://code.google.com/p/dart/wiki/BuildDartSDKOnUbuntu10_04 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2013 Seth Ladd | ||
|
||
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. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Dart + HTTP server | ||
|
||
This server works when [deployed to Heroku][heroku]. | ||
|
||
It's designed to also deploy to Docker, though | ||
that hasn't been tested as thoroughly. | ||
|
||
[heroku]: https://github.com/igrigorik/heroku-buildpack-dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'dart:io' show File, HttpServer, Platform; | ||
import 'dart:async' show runZoned; | ||
import 'package:http_server/http_server.dart' show VirtualDirectory; | ||
import 'package:path/path.dart' show join, dirname; | ||
|
||
void main() { | ||
// Assumes the server lives in bin/ and that `pub build` ran | ||
var pathToBuild = join(dirname(Platform.script.toFilePath()), '..', 'build'); | ||
|
||
var staticFiles = new VirtualDirectory(pathToBuild); | ||
staticFiles.allowDirectoryListing = true; | ||
staticFiles.directoryHandler = (dir, request) { | ||
// Redirect directory-requests to index.html files. | ||
var indexUri = new Uri.file(dir.path).resolve('index.html'); | ||
staticFiles.serveFile(new File(indexUri.toFilePath()), request); | ||
}; | ||
|
||
var portEnv = Platform.environment['PORT']; | ||
var port = portEnv == null ? 9999 : int.parse(portEnv); | ||
|
||
runZoned(() { | ||
HttpServer.bind('0.0.0.0', port).then((server) { | ||
server.listen(staticFiles.serveRequest); | ||
}); | ||
}, | ||
onError: (e, stackTrace) => print('Oh noes! $e $stackTrace')); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
name: dart_on_heroku_demo | ||
name: basic_http_server | ||
author: Seth Ladd <sethladd@gmail.com> | ||
version: 0.0.1 | ||
homepage: https://github.com/sethladd/dart-basic-http-server | ||
description: A sample command-line application | ||
dependencies: | ||
route: any | ||
browser: any | ||
http_server: any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'dart:html'; | ||
|
||
main() { | ||
querySelector('#text').text = 'Hello from Dart!'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<title>Hello from Dart</title> | ||
</head> | ||
|
||
<body> | ||
<p id="text"></p> | ||
|
||
<script type="application/dart" src="index.dart"></script> | ||
<script src="packages/browser/dart.js"></script> | ||
</body> | ||
</html> |