You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
samples/code_sharing/server/bin/server.dart

38 lines
1.1 KiB

import 'dart:convert';
import 'dart:io';
import 'package:shared/shared.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_router/shelf_router.dart';
int count = 0;
// Configure routes.
final _router = Router()
..post('/', _incrementHandler)
..get('/', _getValueHandler);
Future<Response> _incrementHandler(Request request) async {
final incr = Increment.fromJson(json.decode(await request.readAsString()));
count += incr.by;
return Response.ok(json.encode(Count(count).toJson()));
}
Response _getValueHandler(Request request) =>
Response.ok(json.encode(Count(count).toJson()));
void main(List<String> args) async {
// Use any available host or container IP (usually `0.0.0.0`).
final ip = InternetAddress.anyIPv4;
// Configure a pipeline that logs requests.
Bump lints from 2.1.1 to 3.0.0 in /code_sharing/server (#2056) Bumps [lints](https://github.com/dart-lang/lints) from 2.1.1 to 3.0.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/dart-lang/lints/releases">lints's releases</a>.</em></p> <blockquote> <h2>package:lints v3.0.0</h2> <ul> <li><code>core</code>: <ul> <li>added <code>collection_methods_unrelated_type</code></li> <li>added <code>dangling_library_doc_comments</code></li> <li>added <code>implicit_call_tearoffs</code></li> <li>added <code>secure_pubspec_urls</code></li> <li>added <code>type_literal_in_constant_pattern</code></li> <li>added <code>use_string_in_part_of_directives</code></li> <li>removed <code>iterable_contains_unrelated_type</code></li> <li>removed <code>list_remove_unrelated_type</code></li> <li>removed <code>no_wildcard_variable_uses</code></li> </ul> </li> <li><code>recommended</code>: <ul> <li>added <code>unnecessary_to_list_in_spreads</code></li> <li>added <code>use_super_parameters</code></li> <li>removed <code>prefer_equal_for_default_values</code></li> <li>removed <code>prefer_void_to_null</code></li> </ul> </li> <li>Add info about which lints have quick fixes to the package's readme.</li> <li>Move the list of lint rules from the readme to a separate <a href="https://github.com/dart-lang/lints/blob/main/rules.md">rules.md</a> file.</li> </ul> <h2>package:lints v3.0.0-beta.2</h2> <ul> <li>Add <code>dangling_library_doc_comments</code> to core.</li> <li>Remove <code>no_wildcard_variable_uses</code> from core.</li> <li>Remove <code>prefer_void_to_null</code> from recommended.</li> </ul> <h2>package:lints v3.0.0-beta</h2> <ul> <li><code>core</code>: <ul> <li>added <code>collection_methods_unrelated_type</code></li> <li>added <code>implicit_call_tearoffs</code></li> <li>added <code>no_wildcard_variable_uses</code></li> <li>added <code>secure_pubspec_urls</code></li> <li>added <code>type_literal_in_constant_pattern</code></li> <li>added <code>use_string_in_part_of_directives</code></li> <li>removed <code>iterable_contains_unrelated_type</code></li> <li>removed <code>list_remove_unrelated_type</code></li> </ul> </li> <li><code>recommended</code>: <ul> <li>added <code>unnecessary_to_list_in_spreads</code></li> <li>added <code>use_super_parameters</code></li> <li>removed <code>prefer_equal_for_default_values</code></li> </ul> </li> <li>Add info about which lints have quick fixes to the package's readme.</li> <li>Move the list of lint rules from the readme to a separate <a href="https://github.com/dart-lang/lints/blob/main/rules.md">rules.md</a> file.</li> </ul> </blockquote> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/dart-lang/lints/blob/main/CHANGELOG.md">lints's changelog</a>.</em></p> <blockquote> <h2>3.0.0</h2> <ul> <li><code>core</code>: <ul> <li>added <code>collection_methods_unrelated_type</code></li> <li>added <code>dangling_library_doc_comments</code></li> <li>added <code>implicit_call_tearoffs</code></li> <li>added <code>secure_pubspec_urls</code></li> <li>added <code>type_literal_in_constant_pattern</code></li> <li>added <code>use_string_in_part_of_directives</code></li> <li>removed <code>iterable_contains_unrelated_type</code></li> <li>removed <code>list_remove_unrelated_type</code></li> <li>removed <code>no_wildcard_variable_uses</code></li> </ul> </li> <li><code>recommended</code>: <ul> <li>added <code>unnecessary_to_list_in_spreads</code></li> <li>added <code>use_super_parameters</code></li> <li>removed <code>prefer_equal_for_default_values</code></li> <li>removed <code>prefer_void_to_null</code></li> </ul> </li> <li>Add info about which lints have quick fixes to the package's readme.</li> <li>Move the list of lint rules from the readme to a separate <a href="https://github.com/dart-lang/lints/blob/main/rules.md">rules.md</a> file.</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/dart-lang/lints/commit/975c6870682da82fc7460017ec1f0467ee129e37"><code>975c687</code></a> rev to 3.0.0; prep to publish (<a href="https://redirect.github.com/dart-lang/lints/issues/160">#160</a>)</li> <li><a href="https://github.com/dart-lang/lints/commit/90d350eb89fe265c13b5a9c34bfd41e5323896ed"><code>90d350e</code></a> Bump actions/checkout from 3.6.0 to 4.1.0 (<a href="https://redirect.github.com/dart-lang/lints/issues/159">#159</a>)</li> <li><a href="https://github.com/dart-lang/lints/commit/140c8025fe8d31354027670065d7ccb5232b8fe4"><code>140c802</code></a> Bump dart-lang/setup-dart from 1.5.0 to 1.5.1 (<a href="https://redirect.github.com/dart-lang/lints/issues/158">#158</a>)</li> <li><a href="https://github.com/dart-lang/lints/commit/624a09da9c3a8c6cc427bd6358d89cd5f3722652"><code>624a09d</code></a> add dangling_library_doc_comments, remove prefer_void_to_null (<a href="https://redirect.github.com/dart-lang/lints/issues/157">#157</a>)</li> <li><a href="https://github.com/dart-lang/lints/commit/296efaf2914af7c8c3268568ec4f23f3ff33f327"><code>296efaf</code></a> remove no_wildcard_variable_uses; improve testing (<a href="https://redirect.github.com/dart-lang/lints/issues/156">#156</a>)</li> <li><a href="https://github.com/dart-lang/lints/commit/c266a04d9bd6d0ce1bfef76567363a928280b82b"><code>c266a04</code></a> rev to 3.0.0-beta in preparation for publishing (<a href="https://redirect.github.com/dart-lang/lints/issues/153">#153</a>)</li> <li><a href="https://github.com/dart-lang/lints/commit/b044acab9f6669b3d8e781923a8ff86877801177"><code>b044aca</code></a> add several rules to core and recommended (<a href="https://redirect.github.com/dart-lang/lints/issues/150">#150</a>)</li> <li><a href="https://github.com/dart-lang/lints/commit/81100a2ebab8ef272763c404493735de8a39a8e5"><code>81100a2</code></a> fix a dangling table link (<a href="https://redirect.github.com/dart-lang/lints/issues/146">#146</a>)</li> <li><a href="https://github.com/dart-lang/lints/commit/8d5f7500024320654adb1e799e49fc10c5304ae7"><code>8d5f750</code></a> move the list of lint rules from the readme to a separate rules.md file (<a href="https://redirect.github.com/dart-lang/lints/issues/145">#145</a>)</li> <li><a href="https://github.com/dart-lang/lints/commit/da44af3d262d6747a4e700a0916a4e0fd535e305"><code>da44af3</code></a> Bump actions/checkout from 3.5.3 to 3.6.0 (<a href="https://redirect.github.com/dart-lang/lints/issues/144">#144</a>)</li> <li>Additional commits viewable in <a href="https://github.com/dart-lang/lints/compare/v2.1.1...v3.0.0">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=lints&package-manager=pub&previous-version=2.1.1&new-version=3.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Brett Morgan <brettmorgan@google.com>
1 year ago
final handler =
Pipeline().addMiddleware(logRequests()).addHandler(_router.call);
// For running in containers, we respect the PORT environment variable.
final port = int.parse(Platform.environment['PORT'] ?? '8080');
final server = await serve(handler, ip, port);
print('Server listening on port ${server.port}');
}