appengine 0.6.1

  • Installing
  • Versions
  • 78

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
  appengine: '>=0.4.0 <0.5.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.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.6.1

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';
Version Uploaded Documentation Archive
0.6.1 Jan 21, 2019 Go to the documentation of appengine 0.6.1 Download appengine 0.6.1 archive
0.6.0 Jan 18, 2019 Go to the documentation of appengine 0.6.0 Download appengine 0.6.0 archive
0.5.1+1 Jan 11, 2019 Go to the documentation of appengine 0.5.1+1 Download appengine 0.5.1+1 archive
0.5.1 Oct 15, 2018 Go to the documentation of appengine 0.5.1 Download appengine 0.5.1 archive
0.5.0 Aug 17, 2018 Go to the documentation of appengine 0.5.0 Download appengine 0.5.0 archive
0.4.4+2 Jul 16, 2018 Go to the documentation of appengine 0.4.4+2 Download appengine 0.4.4+2 archive
0.4.4+1 Jul 16, 2018 Go to the documentation of appengine 0.4.4+1 Download appengine 0.4.4+1 archive
0.4.4 May 30, 2018 Go to the documentation of appengine 0.4.4 Download appengine 0.4.4 archive
0.4.3+1 Nov 30, 2017 Go to the documentation of appengine 0.4.3+1 Download appengine 0.4.3+1 archive
0.4.3 Nov 30, 2017 Go to the documentation of appengine 0.4.3 Download appengine 0.4.3 archive

All 44 versions...

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 Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.13


Detected platforms: other

Primary library: package:appengine/appengine.dart with components: io, mirrors.

Health suggestions

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

Analysis of lib/src/appengine_internal.dart reported 8 hints, including:

line 8 col 8: Unused import: 'dart:convert'.

line 19 col 8: Unused import: 'package:stack_trace/stack_trace.dart'.

line 31 col 8: Unused import: 'logging.dart'.

line 51 col 14: Use = to separate a named parameter from its default value.

line 51 col 33: Use = to separate a named parameter from its default value.

Fix lib/src/grpc_api_impl/datastore_impl.dart. (-2.48 points)

Analysis of lib/src/grpc_api_impl/datastore_impl.dart reported 5 hints:

line 49 col 29: Use = to separate a named parameter from its default value.

line 143 col 40: Use isNotEmpty instead of length

line 206 col 34: Use isNotEmpty instead of length

line 524 col 57: Use = to separate a named parameter from its default value.

line 541 col 45: Use = to separate a named parameter from its default value.

Fix lib/src/grpc_api_impl/logging_impl.dart. (-1.99 points)

Analysis of lib/src/grpc_api_impl/logging_impl.dart reported 4 hints:

line 103 col 9: Use isNotEmpty instead of length

line 111 col 9: Use isNotEmpty instead of length

line 121 col 29: Use = to separate a named parameter from its default value.

line 292 col 9: Use isEmpty instead of length

Fix additional 6 files with analysis or formatting issues. (-5.98 points)

Additional issues in the following files:

  • lib/src/grpc_api_impl/grpc.dart (3 hints)
  • lib/src/server/server.dart (3 hints)
  • lib/appengine.dart (2 hints)
  • lib/src/api_impl/stderr_logging_impl.dart (2 hints)
  • lib/src/client_context.dart (1 hint)
  • lib/src/errors.dart (1 hint)

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

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.0.0 <3.0.0
fixnum >=0.9.0 <0.11.0 0.10.9
gcloud ^0.6.0 0.6.0+2
googleapis_auth >=0.2.3+6 <0.3.0 0.2.6
http >=0.11.3+9 <0.13.0 0.12.0+1
http2 >=0.1.1+2 <2.0.0 1.0.0
http_server ^0.9.2 0.9.8+1
logging >=0.9.3 <0.12.0 0.11.3+2
path ^1.2.0 1.6.2
protobuf ^0.9.1 0.9.1 0.13.3
stack_trace ^1.9.0 1.9.3
Transitive dependencies
_discoveryapis_commons 0.1.8+1
async 2.0.8
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
googleapis 0.53.0
http_parser 3.1.3
meta 1.1.7
mime 0.9.6+2
source_span 1.5.4
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.3.0