Dart applications can be hosted on the Google Cloud Platform—they run in a custom runtime on App Engine Managed VM. In contrast to the secure, sandboxed environments in which Python, Java, Go, and PHP are run, Dart runs in a VM-based hosting environment, which is more flexible, providing more CPU and memory options.
In the previous chapters, we learned how to write HTTP clients and servers in Dart, which is exactly what we need for a Dart app running in a managed VM.
This environment uses the Docker cloud service to distribute applications. Docker is a tool, written in the Go programming language, to package an application and its dependencies in a virtual container that can run on any Linux server. Docker can be used with various infrastructure tools besides Google Cloud Platform, a few being Amazon Web Services, Chef, Jelastic, Jenkins, Microsoft Azure, OpenStack Nova, OpenSVC, Puppet, and Salt. If you do not develop on Linux, you will need a VM running Linux; boot2docker
is a pre-packaged Linux VM image for VirtualBox.
Go through the following steps to deploy Dart on App Engine:
Use the following steps to create your Dart project:
appengine
package, so add this to your pubspec.yaml
file.app.yaml
file with the following as minimal content:version: app_name runtime: custom vm: true api_version: 1
binserver.dart
file and contain the following start up code:import 'dart:io'; import 'package:appengine/appengine.dart'; (1) main() { runAppEngine((HttpRequest request) { (2) request.response.write(My first Dart App Engine App!') .close(); }); }
In line (1)
, the appengine
package is imported. This includes the top-level runAppEngine()
method, which starts Dart's runtime and connects it to App Engine. This takes an HTTP request handler as callback, which creates the response for the browser.
gcloud preview app run app.yaml
http://localhost:8080
using your browser to see the result and start developing and testing it locally.gcloud preview app deploy app.yaml
After deployment is completed your app can be reached on the World Wide Web (WWW) via http://app_name.appspot.com/
.
Before embarking on your own project, study and experiment with a worked out example of a client-server app available at https://www.dartlang.org/server/google-cloud-platform/app-engine/client-server/. Other examples can be found at https://github.com/dart-lang/appengine_samples.
You can find the latest news on Dart in App Engine on https://www.dartlang.org/server/google-cloud-platform/app-engine/.
For more information on App Engine, consult at https://cloud.google.com/appengine/docs/managed-vms/.
3.135.183.138