appengine 0.10.5

  • Readme
  • Changelog
  • Installing
  • 86

Dart support for Google AppEngine #

This package provides support for running server applications written in Dart on Google App Engine using Custom Runtimes with Flex Environment.

Prerequisites #

Install Dart and Cloud SDKs #

This page assumes the Dart SDK (see as well as the Google Cloud SDK (see were installed and their bin folders have been added to PATH.

Setup gcloud #

To ensure gcloud was authorized to access the cloud project and we have the app component installed, we assume the following has been run:

$ gcloud auth login
$ gcloud config set project <project-name>
$ gcloud components update app

Creation service account #

Furthermore in order to operate on the data of the cloud project, a service account needs to be created which allows downloading a private key in JSON format. Such a key can be obtained via the Cloud Console under IAM & Admin > Service Accounts > Create Service Account.

Creating a hello world application #

To setup a hello world application we need 4 different things:

An app/pubspec.yaml file describing the Dart package:

name: hello_world
version: 0.1.0
  sdk: '>=2.0.0 <3.0.0'

  appengine: ^0.6.0

An app/app.yaml file describing the AppEngine app:

runtime: custom
env: flex
service: default

An app/Dockerfile describing how to build/bundle the app:

FROM google/dart-runtime

### NOTE: Uncomment the following lines for local testing:
#ADD key.json /project/key.json
#ENV GCLOUD_KEY /project/key.json
#ENV GCLOUD_PROJECT dartlang-pub

An app/bin/server.dart containing the app code

import 'dart:io';
import 'package:appengine/appengine.dart';

requestHandler(HttpRequest request) {
      ..write('Hello, world!')

main() async {
  await runAppEngine(requestHandler);

Running the app locally #

There are two ways to run the application locally - with or without docker. Both of which require a service account key.

Running without Docker #

The simplest way to run the application is on the command line like this:

$ export GCLOUD_KEY=<path-to-service-account-key.json>
$ export GCLOUD_PROJECT=<project-name>
$ dart bin/server.dart

This will serve the application at localhost:8080!

Running with Docker #

To be closer to the production environment one can run the application inside a docker container. In order to do so, docker needs to be installed first (see the official instructions.

In order to run the application locally we uncomment the 3 lines in the Dockerfile and place the service account key in under app/key.json:

ADD key.json /project/key.json
ENV GCLOUD_KEY /project/key.json

We can then run the application via:

$ docker build .
Sucessfully built <docker-imgage-hash>
$ docker run -it <docker-imgage-hash>

In order to find out at which IP the Docker container is available we inspect the running container via:

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
<container-id>       ...
app % docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-id>

Then the application will be available at

Deployment #

Before deploying the app, be sure to remove the environment variables in the Dockerfile which we used for local testing!

To deploy the application to the cloud we run the following command (optionally passing the --no-promote flag to avoid replacing the production version)

$ gcloud app deploy --no-promote app.yaml
Updating service [default]...done.
Deployed service [default] to [https://<version-id>-dot-<project-id>]

This will perform a remote docker build in the cloud and deploy a new version. You can find the URL to the version that got deployed in the output of gcloud app deploy (as well as via the Cloud Console under AppEngine > Versions).

Using the datastore emulator #

The gcloud sdk provides an easy-to-use datastore emulator. The emulator can be launched via

$ gcloud beta emulators datastore start
[datastore] If you are using a library that supports the DATASTORE_EMULATOR_HOST
[datastore] environment variable, run:
[datastore]   export DATASTORE_EMULATOR_HOST=localhost:8268
[datastore] Dev App Server is now running.

To make the application use the emulator, the DATASTORE_EMULATOR_HOST environment variable needs to be set (in addition to the other variables):

$ export DATASTORE_EMULATOR_HOST=localhost:8268
$ export GCLOUD_KEY=<path-to-service-account-key.json>
$ export GCLOUD_PROJECT=<project-name>
$ dart bin/server.dart

0.10.5 #

  • Handle duplicate user-agent headers.

0.10.4 #

  • Added Logging.reportError to the `logging interface, for reporting errors to Stackdriver Error Reporting when running in AppEngine.
  • Report errors logged through the package:logging adapter to Logging.reportError (for reporting to Stackdriver Error Reporting).
  • Updated protobuf source files.
  • Reduced number of unnecessarily generated protos.

0.10.3 #

  • Update Protobuf to v1.0.0
  • Add client library identification header
  • Fix grpc/datastore tests

0.10.2 #

  • Update gRPC version dependency

0.10.1 #

  • Update gRPC API protos

0.10.0 #

  • Revert 0.9.0

0.9.0 #

  • Instantiate new DatastoreDB instances for each request.

0.8.1 #

  • Detect dev mode when running behind a proxy.

0.8.0 #

  • Add applicationContext getter to ClientContext

0.7.3 #

  • Add onAcceptingConnections callback to runAppEngine()

0.7.2 #

  • Update the generated protobufs.

0.7.1 #

  • Update to use package:grpc version 2.0

0.7.0 #

  • Refactored to use package:grpc to talk to Logging and Datastore backends.

0.6.1 #

  • Added isCronJonRequest as a helper method for determining if a request originates from the AppEngine cronjob scheduler.

0.6.0 #

Breaking changes:

  • Removed poorly documented assets support with broken tests.
  • Removed memcache as the service was never made it past alpha.

Users of memcache should consider using Cloud Memorystore instead. This comes with a redis interface for which there are multiple packages available on pub. Serving assets is just a matter of sending a file from disk. This is easy to do without the logic that this package used to contain.

0.5.1+1 #

  • Support latest pkg:http and pkg:http2.

0.5.1 #

  • Correct root path for serving assets.

0.5.0 #

  • Support for Dart 2.0 constants and updated gcloud.

0.4.4+2 #

  • Fix race condition in gRPC client between http2Connection.isOpen and http2Connection.makeRequest.

0.4.4+1 #

  • Delay http/2 connection dialer by 20 ms to give client enough time to receive server settings.

0.4.4 #

  • Improve output logging when memcache connections fail.
  • Fix Dart 2 runtime issues.

0.4.3+1 #

  • When logging requests, the label is populated.

0.4.3 #

  • When logging, the following protoPayload values are now populated:

    • instanceId
    • referrer
    • traceId via the X-Cloud-Trace-Context request header.
  • The label is also populated for all log entries.

  • traceId was also added to the ClientContext class.

0.4.2 #

  • Add support for connecting to memcache instance defined by environment variables GAE_MEMCACHE_HOST and GAE_MEMCACHE_PORT.

0.4.1 #

  • Add shared option to runAppEngine to enable multi-threaded operation with isolates.

0.4.0+3 #

  • Fix an issue where models with un-indexed list properties could not be committed.

0.4.0+2 #

  • Be less verbose in request logs printed during local development

0.4.0 #

Switch from Managed VMs to Flexible environment:

  • Removed UsersService api.
  • Removed ModulesService api.
  • Removed RemoteApi api (was already deprecated).
  • Introduce new GCLOUD_PROJECT and GCLOUD_KEY environment variables.
  • Remove STORAGE_SERVICE_ACCOUNT_FILE environment variable.
  • To prevent duplicate logging of errors, runAppEngine will no longer log request-specific errors on stdout if they got already logged via the request-specific log.

0.3.3+1 #

  • Support gcloud package version 0.3.0.

0.3.3 #

  • Work around issue (it doesn't drain stdout we therefore avoid printing anything).

0.3.2 #

  • Require protobuf package ^0.5.0
  • Support the lastest release of fixnum package.

0.3.1+1 #

  • Improved output of Logger.root with useLoggingPackageAdaptor.

0.3.1 #

  • Added optional port argument to runAppEngine.
  • Removed the call to /bin/hostname.

0.3.0+1 #

  • Widen dependency constraint on package:logging.

0.3.0 #

  • Pass the memcache expiration time to the memcache service. Before the expiration argument to Memcache.set and Memcache.setAll was ignored.

  • Removed the expiration argument to Memcache.clear. It is not supported by the App Engine memcache API.

0.2.6+3 #

  • Update dependencies to allow gcloud 0.2.0 with Cloud Pub/Sub support.

0.2.6+2 #

  • Do not close authClient, since registerStorageService does it automatically.

0.2.6+1 #

  • Correctly handling x-appengine-https header.
  • Turn logging of for Level.OFF

0.2.6 #

  • Added adaptor for package:logging via useLoggingPackageAdaptor().
  • Added workaround for incorrect requestedUri comming from 'dart:io'.

0.2.5 #

  • Added withAppEngineServices() function which allows running arbitrary code using AppEngine services via a service scope.

0.2.4+1 #

  • Change the service scope keys keys to non-private symbols.

0.2.4 #

  • Run request handlers inside a service scope (see package:gcloud/service_scope.dart).
  • Insert an authenticated HTTP client into the service scope.
  • Insert a memcacheService into the service scope.
  • Added isDevelopmentServer and isProductionEnvironment getter to client context.
  • Make hostnames returned from modules service use -dot- naming to support HTTPS.
  • Mark package:appengine/remote_api.dart as deprecated.

0.2.3 #

  • Small bugfix in the lowlevel memcache API implementation.

0.2.2 #

  • Updated
  • Widen googleapis_auth constraint to include version 0.2.0

0.2.1 #

  • Small bugfix in storage API implementation
  • respect DART_PUB_SERVE url only in developer mode
  • sync db/datastore tests to the ones used in gcloud

0.2.0 #

  • Use datastore/db APIs from package:gcloud
    • simplified annotation system
    • paging-based query API
  • Added module service
  • Some bugfixes

0.1.0 #

  • Alpha release

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  appengine: ^0.10.5

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:appengine/appengine.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/appengine_internal.dart. (-0.50 points)

Analysis of lib/src/appengine_internal.dart reported 1 hint:

line 17 col 8: Unused import: 'package:grpc/src/client/channel.dart'.

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and appengine.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
fixnum ^0.10.0 0.10.11
gcloud ^0.6.0 0.6.3
googleapis_auth ^0.2.8 0.2.11+1
grpc ^2.1.0 2.1.3
http ^0.12.0 0.12.0+4
http2 ^1.0.0 1.0.0
http_server ^0.9.2 0.9.8+3
logging ^0.11.0 0.11.4
path ^1.6.0 1.6.4
protobuf ^1.0.0 1.0.1
stack_trace ^1.9.0 1.9.3
Transitive dependencies
_discoveryapis_commons 0.1.9
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
googleapis 0.54.0
http_parser 3.1.4
meta 1.1.8
mime 0.9.6+3
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.8.0 1.9.0
test ^1.6.0