@@ -8,76 +8,33 @@ that you can use for testing. It reads in the env variable `TARGET` and prints
88## Prerequisites
99
1010- A Kubernetes cluster with Knative installed and DNS configured. Follow the
11- [ Knative installation instructions] ( https://knative.dev/docs/install/ ) if you need to create
12- one.
11+ [ Knative installation instructions] ( https://knative.dev/docs/install/ ) if
12+ you need to create one.
1313- [ Docker] ( https://www.docker.com ) installed and running on your local machine,
1414 and a Docker Hub account configured (we'll use it for a container registry).
15- - [ dart-sdk ] ( https://www. dart.dev/tools/sdk#install ) installed and
15+ - The [ Dart SDK ] ( https://dart.dev/get-dart ) installed and
1616 configured if you want to run the program locally.
1717
1818## Recreating the sample code
1919
20- While you can clone all of the code from this directory, it is useful to know
21- how to build a hello world Dart application step-by-step . This application can
22- be created using the following instructions.
20+ While you can clone all of the code from this directory, we recommend you create
21+ your hello world Dart application by using the ` dart ` developer tool . This takes
22+ just a few steps:
2323
24- 1 . Create a new directory and write ` pubspec.yaml ` as follows :
24+ 1 . Create a new Dart app using the ` server_shelf ` template :
2525
26- ``` yaml
27- name : hello_world_dart
28- publish_to : none # let's not accidentally publish this to pub.dartlang.org
29-
30- environment :
31- sdk : " >=2.12.0 <3.0.0"
32-
33- dependencies :
34- shelf : ^1.0.0
26+ ``` shell
27+ > dart create -t server-shelf helloworld-dart
3528 ```
3629
37- 2 . If you want to run locally, install dependencies. If you only want to run in
30+ 1 . If you want to run locally, install dependencies. If you only want to run in
3831 Docker or Knative, you can skip this step.
3932
40- ` ` ` bash
41- > pub get
42- ```
43-
44- 3 . Create a new file ` bin/server.dart ` and write the following code:
45-
46- ``` dart
47- import 'dart:io';
48-
49- import 'package:shelf/shelf.dart';
50- import 'package:shelf/shelf_io.dart';
51-
52- Future main() async {
53- // Find port to listen on from environment variable.
54- final port = int.parse(Platform.environment['PORT'] ?? '8080');
55-
56- // Read $TARGET from environment variable.
57- final target = Platform.environment['TARGET'] ?? 'World';
58-
59- Response handler(Request request) => Response.ok('Hello $target');
60-
61- // Serve handler on given port.
62- final server = await serve(
63- const Pipeline().addMiddleware(logRequests()).addHandler(handler),
64- InternetAddress.anyIPv4,
65- port,
66- );
67- print('Serving at http://${server.address.host}:${server.port}');
68- }
69- ```
70-
71- 4 . Create a new file named ` Dockerfile ` , this file defines instructions for
72- dockerizing your applications, for dart apps this can be done as follows:
73-
74- ``` Dockerfile
75- # Use Google's official Dart image.
76- # https://hub.docker.com/r/google/dart-runtime/
77- FROM google/dart-runtime
33+ ``` shell
34+ > dart pub get
7835 ```
7936
80- 5 . Create a new file, ` service.yaml ` and copy the following service definition
37+ 1 . Create a new file, ` service.yaml ` and copy the following service definition
8138 into the file. Make sure to replace ` {username} ` with your Docker Hub
8239 username.
8340
0 commit comments