astra_cli 1.0.0-dev.26 copy "astra_cli: ^1.0.0-dev.26" to clipboard
astra_cli: ^1.0.0-dev.26 copied to clipboard

unlisted

The Astra/Shelf CLI tool.

Pub Package License

The astra and shelf command line tool. Inspired by uvicorn.

WORK IN PROGRESS

ToDo #

  • Verbose output 🔥
  • Logging 🔥
  • Tests 🔥
  • Environment variables & configuration file
  • Commands:
    • create
    • generate
    • build
    • ...
  • ...

Experimenting #

  • Serving package URI (if possible) 🤔
  • build_runner integration

Quickstart #

Install using dart pub:

$ dart pub global activate astra_cli

Create an application with lib/[package].dart file:

import 'dart:io';

import 'package:astra/core.dart';

Response application(Request request) {
  return Response.ok('hello world!');
}

Run the server:

$ astra serve

Usage #

Run serve command to serve your application:

Serve Astra/Shelf application.

Usage: astra serve [options]
-h, --help                                Print this usage information.

Application options:
-t, --target=<application>                Application target.
    --target-path=<lib/[package].dart>    Application target location.
                                          Must be within application root folder.
-C, --directory=<.>                       Application root folder.
-D, --define=<key=value>                  Define an environment declaration.

Server options:
-a, --address=<localhost>                 Bind server to this address.
                                          Bind will perform a InternetAddress.lookup and use the first value in the list.
-p, --port=<8080>                         Bind server to this port.
                                          If port has the value 0 an ephemeral port will be chosen by the system.
                                          The actual port used can be retrieved using the port getter.
    --ssl-key=<file.key>                  SSL key file.
    --ssl-cert=<file.crt>                 SSL certificate file.
    --ssl-key-password=<password>         SSL keyfile password.
    --backlog=<0>                         Number of connections to hold in backlog.
                                          If it has the value of 0 a reasonable value will be chosen by the system.
    --v6Only                              Restrict IP addresses to version 6 (IPv6) only.
                                          If an IP version 6 (IPv6) address is used, both IP version 6 (IPv6) and version 4 (IPv4) connections will be accepted.
    --shared                              Specifies whether additional servers can bind to the same combination of address, port and v6Only.
                                          If it's true and more servers are bound to the port, then the incoming connections will be distributed among all the bound servers.
    --server-type=<shelf>                 Server type.

          [shelf]                         HTTP/1.x shelf server.

-i, --isolates=<1>                        Number of isolates.

Debugging options:
    --debug
    --hot-reload
-w, --watch
    --service-port=<8181>
    --enable-asserts
-v, --verbose                             Print detailed logging.

Run "astra help" to see global options.

Running programmatically #

To run server directly from your application:

bin/main.dart

import 'package:astra/serve.dart';
import 'package:example/example.dart';

Future<void> main() async {
  var server = await application.serve('localhost', 8080);
  print('Serving at ${server.url} ...');
}