Serving content dynamically using the directory parameter for GET requests – shelf package dart

Issue The code snippets below come from a server serving a get request Server snippets 1) io.serve(handler, InternetAddress.LOOPBACK_IP_V4, 8080).then((server) { print(‘Listening on port 8080’); }).catchError((error) => print(error)); 2) Router routes = new Router() ..get(‘/newest’, handler.handleNewest) ..get(‘/anonymous’, handler.handleAnonymousGetRequest) ..post(‘/anonymous’, handler.handleAnonymousPostRequest); 3)

Continue reading

Incompatibility between the Dart shelf and rpc packages? ('access-control-request-method' header)

Issue There seems to be an incompatibility between the shelf and rpc packages. In rpc [0.4.1] config/api.dart: The handleHttpOptionsRequest expects the ‘access-control-request-method’ header to be a List: Future<HttpApiResponse> handleHttpOptionsRequest( ParsedHttpApiRequest request) async { var requestedHttpMethods = request.headers[‘access-control-request-method’]; List<String> allowed =

Continue reading

Separating a Cascade in Dart

Issue I’m seeing some weird behavior in Dart. My goal is to only serve static assets if a build/web Dir exists. 1- The following works: Cascade cc; if(new Directory(buildPath).existsSync() ) { cc = new Cascade().add(apiHandler).add(fHandler); } else { cc =

Continue reading

Unit testing with dart's shelf_rest

Issue I’m trying to test a Dart REST app run on shelf_rest. Assuming a setup similar to the shelf_rest example, how can one test the configured routes without actually running an HTTP server? import ‘package:shelf/shelf.dart’; import ‘package:shelf/shelf_io.dart’ as io; import

Continue reading